private static void OnExtendedSelectionEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ListBoxExtendedSelectionBehavior listBoxExtendedSelectionBehavior = d as ListBoxExtendedSelectionBehavior; bool?newValue = (bool?)(e.NewValue as bool?); if (listBoxExtendedSelectionBehavior != null && newValue.HasValue && listBoxExtendedSelectionBehavior.IsEnabled) { if (!newValue.Value) { object selectedItem = listBoxExtendedSelectionBehavior.AssociatedObject.SelectedItem; if (listBoxExtendedSelectionBehavior.AssociatedObject.SelectedItems.Count > 1) { listBoxExtendedSelectionBehavior.AssociatedObject.SelectedItems.Clear(); } if (selectedItem != null) { listBoxExtendedSelectionBehavior.AssociatedObject.SelectedItems.Add(selectedItem); } } else if (listBoxExtendedSelectionBehavior.AssociatedObject.SelectedItems.Count == 1) { listBoxExtendedSelectionBehavior.AssociatedObject.SelectedItem = null; } ListBoxExtendedSelectionBehavior.SetExtendedSelectionEnabledAttached(listBoxExtendedSelectionBehavior.AssociatedObject, newValue.Value); } }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this._listBoxExtendedSelectionBehavior = ((SmartView2.Behaviors.ListBoxExtendedSelectionBehavior)(target)); return; } this._contentLoaded = true; }
private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { ListBoxExtendedSelectionBehavior listBoxExtendedSelectionBehavior = d as ListBoxExtendedSelectionBehavior; bool?newValue = (bool?)(e.NewValue as bool?); if (listBoxExtendedSelectionBehavior != null && newValue.HasValue && listBoxExtendedSelectionBehavior.AssociatedObject != null) { ListBoxExtendedSelectionBehavior.SetIsEnabledAttached(listBoxExtendedSelectionBehavior.AssociatedObject, newValue.Value); bool?nullable = newValue; if ((nullable.GetValueOrDefault() ? false : nullable.HasValue)) { listBoxExtendedSelectionBehavior.ExtendedSelectionEnabled = false; listBoxExtendedSelectionBehavior.SelectedItems = null; ListBoxExtendedSelectionBehavior.SetExtendedSelectionEnabledAttached(listBoxExtendedSelectionBehavior.AssociatedObject, false); } } }