예제 #1
0
        private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MyRibbonGalleryItem container = (MyRibbonGalleryItem)d;
            bool newValue = (bool)e.NewValue;
            MyRibbonGalleryCategory ribbonGalleryCategory = container.RibbonGalleryCategory;

            if (ribbonGalleryCategory == null)
            {
                return;
            }
            MyRibbonGallery ribbonGallery = ribbonGalleryCategory.RibbonGallery;

            if (ribbonGallery == null)
            {
                return;
            }
            object obj = ribbonGalleryCategory.ItemContainerGenerator.ItemFromContainer((DependencyObject)container);

            if (obj == DependencyProperty.UnsetValue)
            {
                obj = (object)container;
            }
            ribbonGallery.ChangeSelection(obj, container, newValue);
            Debug.WriteLine("hello");
        }
예제 #2
0
        public void ChangeSelection(object item, MyRibbonGalleryItem container, bool isSelected)
        {
            if (this.IsSelectionChangeActive)
            {
                return;
            }
            object selectedItem = this.SelectedItem;
            object itemValue    = item;
            bool   flag         = !MyRibbonGallery.VerifyEqual(selectedItem, itemValue);

            try
            {
                Debug.WriteLine("here");
                this.IsSelectionChangeActive = true;
                if (isSelected == flag)
                {
                    Debug.WriteLine("here1");
                    if (!isSelected && container != null)
                    {
                        Debug.WriteLine("here2");
                        container.IsSelected = false;
                        int index = this._selectedContainers.IndexOf(container);
                        if (index > -1)
                        {
                            Debug.WriteLine("here3");
                            this._selectedContainers.RemoveAt(index);
                            container.OnUnselected_(new RoutedEventArgs(RibbonGalleryItem.UnselectedEvent, (object)container));
                        }
                    }
                    else
                    {
                        Debug.WriteLine("here4");
                        for (int index = 0; index < this._selectedContainers.Count; ++index)
                        {
                            MyRibbonGalleryItem selectedContainer = (MyRibbonGalleryItem)this._selectedContainers[index];
                            selectedContainer.IsSelected = false;
                            selectedContainer.OnUnselected_(new RoutedEventArgs(RibbonGalleryItem.UnselectedEvent, (object)selectedContainer));
                            if (!isSelected)
                            {
                                Debug.WriteLine("here5");
                                this.MoveCurrentToPosition_(selectedContainer.RibbonGalleryCategory.CollectionView, -1);
                            }
                        }
                        this._selectedContainers.Clear();
                        if (!isSelected)
                        {
                            Debug.WriteLine("here6");
                            this.InvalidateProperty(RibbonGallery.SelectedItemProperty);
                            this.InvalidateProperty(RibbonGallery.SelectedValueProperty);
                            this.MoveCurrentToPosition_(this.CollectionView, -1);
                            this.MoveCurrentToPosition_(this.SourceCollectionView, -1);
                            if (LogicalTreeHelper.GetParent((DependencyObject)this) is MyRibbonComboBox parent && this == parent.FirstGallery && !parent.IsSelectedItemCached)
                            {
                                parent.UpdateSelectionProperties_();
                            }
                        }
                    }
                    if (isSelected)
                    {
                        Debug.WriteLine("here7");
                        this.SetCurrentValue(RibbonGallery.SelectedItemProperty, item);
                        this.SetCurrentValue(RibbonGallery.SelectedValueProperty, this.GetSelectableValueFromItem(item));
                        if (container != null)
                        {
                            this.SynchronizeWithCurrentItem(container.RibbonGalleryCategory, item);
                        }
                        else
                        {
                            this.SynchronizeWithCurrentItem();
                        }
                    }
                }
                if (isSelected)
                {
                    Debug.WriteLine("here8");
                    if (container != null)
                    {
                        Debug.WriteLine("here9");
                        if (!this._selectedContainers.Contains(container))
                        {
                            Debug.WriteLine("her10e");
                            this._selectedContainers.Add(container);
                            container.IsSelected = true;
                            container.OnSelected_(new RoutedEventArgs(RibbonGalleryItem.SelectedEvent, (object)container));
                        }
                    }
                }
            }
            finally
            {
                this.IsSelectionChangeActive = false;
            }

            if (!flag)
            {
                Debug.WriteLine("here11");
                return;
            }

            Debug.WriteLine("here12");
            this.OnSelectionChanged(new RoutedPropertyChangedEventArgs <object>(selectedItem, isSelected ? itemValue : (object)null, RibbonGallery.SelectionChangedEvent));
        }