我有一個行爲來支持列表框中的selectedItems。這裏是代碼的一部分。 有沒有一種方法,如果目標又名AssociatedObject.SelectedItems爲空來創建它的一個實例?所有我嘗試失敗...從列表行爲創建實例
void ContextSelectedItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
//Need to unsubscribe from the events so we don't override the transfer
UnsubscribeFromEvents();
//Move items from the selected items list to the list box selection
Transfer(SelectedItems as IList, AssociatedObject.SelectedItems);
//subscribe to the events again so we know when changes are made
SubscribeToEvents();
}
public static void Transfer(IList source, IList target)
{
if (source == null || target == null)
{
return;
}
target.Clear();
foreach (var o in source)
{
target.Add(o);
}
}
UPDATE
這裏是我的代碼的來源。 http://blog.bdcsoft.com/developer-blog/2011/no-binding-for-you-a-listbox-selecteditems-behavior-solution/
它是一種行爲。 http://blog.bdcsoft.com/developer-blog/2011/no-binding-for-you-a-listbox-selecteditems-behavior-solution/。然而,收集應該初始化:( – GorillaApe
@Parhs。是的,它是一個行爲,是的,mathieu告訴你什麼是錯誤的。看到我張貼的示例代碼。乾杯 – Berryl