リストボックスでselectedItemsをサポートする動作があります。そして、これがコードの一部です。ターゲット別名 AssociatedObject.SelectedItemsが null の場合、そのインスタンスを作成する方法はありますか? 私が試したことはすべて失敗しました...
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);
}
}
アップデート
これが私のコードの由来です。 http://blog.bdcsoft.com/developer-blog/2011/no-binding-for-you-a-listbox-selecteditems-behavior-solution/