Пример #1
0
 protected virtual void OnItemSelectionChanging(ItemSelectionChangingEventArgs args)
 {
     if (ItemSelectionChanging != null)
     {
         ItemSelectionChanging(this, args);
     }
 }
Пример #2
0
        private void OnItemSelectionChangedCore(RoutedEventArgs args, bool unselected)
        {
            object item = this.ItemContainerGenerator.ItemFromContainer((DependencyObject)args.OriginalSource);

            // When the item is it's own container, "UnsetValue" will be returned.
            if (item == DependencyProperty.UnsetValue)
            {
                item = args.OriginalSource;
            }

            var itemselectionChangingArgs = new ItemSelectionChangingEventArgs(item, !unselected);

            this.OnItemSelectionChanging(itemselectionChangingArgs);
            if (itemselectionChangingArgs.Cancel)
            {
                this.UpdateSelectorItem(item, unselected, false);
                return;
            }

            if (unselected)
            {
                while (SelectedItems.Contains(item))
                {
                    SelectedItems.Remove(item);
                }
            }
            else
            {
                if (!SelectedItems.Contains(item))
                {
                    SelectedItems.Add(item);
                }
            }
        }