我有一种行为来支持列表框中的 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);
}
}
更新