You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicstaticclassListBoxHelper{publicstatic IList GetSelectedItems(ListBoxlistBox){return(IList)listBox.GetValue(SelectedItemsProperty);}publicstaticvoidSetSelectedItems(ListBoxlistBox,IListvalue){thrownew Exception("This property is read-only. To bind to it you must use 'Mode=OneWayToSource'.");}publicstaticreadonlyDependencyPropertySelectedItemsProperty=
DependencyProperty.RegisterAttached("SelectedItems",typeof(IList),typeof(ListBoxHelper),new FrameworkPropertyMetadata(null, OnSelectedItemsChanged));privatestaticvoidOnSelectedItemsChanged(DependencyObjectobj,DependencyPropertyChangedEventArgse){if(obj is not ListBox listBox)return;
InitializeSelectedItems(listBox);
listBox.SelectionChanged +=ListBox_SelectionChanged;staticvoidInitializeSelectedItems(ListBoxlistBox){if(GetSelectedItems(listBox)is not IList list)return;
list.Clear();foreach(var item in listBox.SelectedItems)
list.Add(item);}staticvoidListBox_SelectionChanged(objectsender,SelectionChangedEventArgse){if(sender is not ListBox listBox)return;if(GetSelectedItems(listBox)is not IList list)return;foreach(var item in e.RemovedItems)
list.Remove(item);foreach(var item in e.AddedItems)
list.Add(item);}}}
No description provided.
The text was updated successfully, but these errors were encountered: