void listBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { var listBox = sender as System.Windows.Controls.ListBox; //listBox.IsSynchronizedWithCurrentItem = true; if (listBox.SelectedItems.Count == 0) { listBox.SelectedIndex = 0; } //消除PropertyChanged if (_previousSelectedItem != null) { var notify = (INotifyPropertyChanged)_previousSelectedItem; notify.PropertyChanged -= Item_PropertyChanged; foreach (var item in _previousSubItems) { item.PropertyChanged -= SubItem_PropertyChanged; } _previousSubItems.Clear(); } if (listBox.SelectedItems.Count > 1) //>1时,开启多选监听 { var item = (INotifyPropertyChanged)listBox.SelectedItem; _previousSelectedItem = item; item.PropertyChanged += Item_PropertyChanged; //子属性 _multiUpdateProperties = _listBox.GetValue(ItemsElementBehavior.MultiUpdatePropertyNamesProperty) as IList; var deepProperties = _multiUpdateProperties.Cast <string>().Where(s => s.Contains('.')); if (deepProperties.Count() > 0) { foreach (var property in deepProperties) { var array = property.Split('.'); var index = array.Length - 1; var subItem = item.GetValueByIndex(property, index); if (subItem is INotifyPropertyChanged) { var notify = subItem as INotifyPropertyChanged; notify.PropertyChanged += SubItem_PropertyChanged; _previousSubItems.Add(notify); } } } } else { _previousSelectedItem = null; } }
public static void SetHasBindableSelectedItems(ListBox source, bool value) { SelectionChangedHandler Handler = (SelectionChangedHandler)source.GetValue(SelectionChangedHandlerProperty); if (value && Handler == null) { Handler = new SelectionChangedHandler(source); source.SetValue(SelectionChangedHandlerProperty, Handler); } else if (!value && Handler != null) { source.ClearValue(SelectionChangedHandlerProperty); } }
private static ListSelectCommandBehavior GetOrCreateBehavior(ListBox selector) { var behavior = selector.GetValue(SelectCommandBehaviorProperty) as ListSelectCommandBehavior; if (behavior == null) { behavior = new ListSelectCommandBehavior(selector); selector.SetValue(SelectCommandBehaviorProperty, behavior); } return behavior; }
private static SelectedItemsBehavior GetOrCreateBehavior(ListBox target, IList list) { var behavior = target.GetValue(SelectedItemsBehaviorProperty) as SelectedItemsBehavior; if (behavior == null) { behavior = new SelectedItemsBehavior(target, list); target.SetValue(SelectedItemsBehaviorProperty, behavior); } return behavior; }
private static ListBoxSelectionChangedCommandBehavior GetOrCreateBehavior(ListBox ListBox) { ListBoxSelectionChangedCommandBehavior behavior = ListBox.GetValue(SelectCommandBehaviorProperty) as ListBoxSelectionChangedCommandBehavior; if (behavior == null) { behavior = new ListBoxSelectionChangedCommandBehavior(ListBox); ListBox.SetValue(SelectCommandBehaviorProperty, behavior); } return behavior; }
public static void SetAutoScroll(ListBox instance, bool value) { var oldHandler = (AutoScrollHandler)instance.GetValue(AutoScrollHandlerProperty); if (oldHandler != null) { oldHandler.Dispose(); instance.SetValue(AutoScrollHandlerProperty, null); } instance.SetValue(AutoScrollProperty, value); if (value) instance.SetValue(AutoScrollHandlerProperty, new AutoScrollHandler(instance)); }
public static void SetForceSingleSelectionModeItemIndex(System.Windows.Controls.ListBox source, int value) { if (source != null) { source.SelectionChanged += (sender, e) => { if (e.AddedItems.Count == 0) { return; } var selectedItem = e.AddedItems[0]; var lb = sender as System.Windows.Controls.ListBox; var selectedIndex = lb.Items.IndexOf(selectedItem); var itemIndexValue = (int)source.GetValue(ForceSingleSelectionModeItemIndexProperty); var selectedItems = (IList)source.GetValue(BindableSelectedItemsProperty); if (selectedIndex == itemIndexValue) { foreach (var item in lb.Items) { if (item != selectedItem) { if (selectedItems.Contains(item)) { selectedItems.Remove(item); } } } } else { selectedItems.Remove(lb.Items[itemIndexValue]); } }; source.SetValue(ForceSingleSelectionModeItemIndexProperty, value); } }
public static void SetHasBindableSelectedItems(System.Windows.Controls.ListBox source, bool value) { var handler = (SelectionChangedHandler)source.GetValue(SelectionChangedHandlerProperty); if (value && handler == null) { handler = new SelectionChangedHandler(source); source.SetValue(SelectionChangedHandlerProperty, handler); } else if (!value && handler != null) { source.ClearValue(SelectionChangedHandlerProperty); } }
public static void SetAutoScroll(System.Windows.Controls.ListBox instance, bool value) { AutoScrollHandler OldHandler = (AutoScrollHandler)instance.GetValue(AutoScrollHandlerProperty); if (OldHandler != null) { OldHandler.Dispose(); instance.SetValue(AutoScrollHandlerProperty, null); } instance.SetValue(AutoScrollProperty, value); if (value) { instance.SetValue(AutoScrollHandlerProperty, new AutoScrollHandler(instance)); } }
private static ListChangedHandler GetChangedHandler(ListBox obj) { return (ListChangedHandler)obj.GetValue(ChangedHandlerProperty); }
public static bool GetIsActivatable(ListBox obj) { return (bool)obj.GetValue(IsActivatableProperty); }
public static IList GetItems(ListBox listBox) { return listBox.GetValue(ItemsProperty) as IList; }
public static bool GetIsListboxItemBringIntoView(ListBox listBox) { return (bool)listBox.GetValue(IsListboxItemBringIntoViewProperty); }
public static bool GetIsSelectedItemScrolledIntoView(ListBox listBox) { return (bool)listBox.GetValue(IsSelectedItemScrolledIntoViewProperty); }
private void DragStarted(ListBox listbox) { listbox.ClearValue(IsDownProperty); // SetValue to false would also work. // Add the bound item, available as DraggingElement, to a DataObject, however we see fit. Artist draggingElement = (Artist)listbox.GetValue(DraggingElementProperty); DataObject d = new DataObject(DataFormats.Dif, draggingElement); DragDropEffects effects = DragDrop.DoDragDrop(listbox, d, DragDropEffects.Copy); if ((effects & DragDropEffects.Move) != 0) { // Move rather than copy, so we should remove from bound list. DataList<Artist> collection = (DataList<Artist>)listbox.ItemsSource; collection.Remove(draggingElement); } }
/// <summary> /// Retrieves the <see cref="ICommand"/> attached to the <see cref="TextBox"/>. /// </summary> /// <param name="selector">TextBox containing the Command dependency property</param> /// <returns>The value of the command attached</returns> public static ICommand GetCommand(ListBox selector) { return selector.GetValue(CommandProperty) as ICommand; }
public static bool GetAutoScroll(ListBox instance) { return (bool)instance.GetValue(AutoScrollProperty); }
public static bool GetIsAutoCenterItem(ListBox element) { return (bool)element.GetValue(IsAutoCenterItemProperty); }
public static bool GetCenterSelectedItemOnLoad(ListBox ListBox) { return (bool)ListBox.GetValue(CenterSelectedItemOnLoadProperty); }
public static bool GetIsBroughtIntoViewWhenInserted(ListBox listBox) { return (bool)listBox.GetValue(IsBroughtIntoViewWhenInsertedProperty); }
public static bool GetAutoScroll(System.Windows.Controls.ListBox instance) { return((bool)instance.GetValue(AutoScrollProperty)); }
public void B_should_return_default_from_GetValue() { var listBox = new ListBox(); listBox.GetValue(MyObjectWithDefaultValue.MyTextProperty).ToString().ShouldBe("default"); }
public static ICommand GetCommand(ListBox ListBox) { return (ListBox.GetValue(CommandProperty) as ICommand); }
public static ListBoxMouseWheelScroller GetListBoxMouseWheelScroller(ListBox element) { return (ListBoxMouseWheelScroller)element.GetValue(ListBoxMouseWheelScrollerProperty); }
public static bool GetIsScrollIntoViewWhenSelected(System.Windows.Controls.ListBox obj) { return((bool)obj.GetValue(IsScrollIntoViewWhenSelectedProperty)); }
public static bool GetSelectedItemsBinding(ListBox element) { return (bool)element.GetValue(SelectedItemsProperty); }
public static object GetCommandParameter(ListBox ListBox) { return (ListBox.GetValue(CommandParameterProperty)); }