Beispiel #1
0
        /// <summary>
        /// Handles Command changed
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnCommandChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonControl control = d as RibbonControl;
            EventHandler  handler = control.OnCommandCanExecuteChanged;

            if (e.OldValue != null)
            {
                (e.OldValue as ICommand).CanExecuteChanged -= handler;
            }
            if (e.NewValue != null)
            {
                handler = new EventHandler(control.OnCommandCanExecuteChanged);
                control.canExecuteChangedHandler            = handler;
                (e.NewValue as ICommand).CanExecuteChanged += handler;

                RoutedUICommand cmd = e.NewValue as RoutedUICommand;
                if ((cmd != null) && (control.Header == null))
                {
                    control.Header = cmd.Text;
                }
            }
            control.UpdateCanExecute();
        }
Beispiel #2
0
        void Refresh()
        {
            // Clear currently used group containers
            // and supply with new generated ones
            foreach (GalleryGroupContainer galleryGroupContainer in galleryGroupContainers)
            {
                BindingOperations.ClearAllBindings(galleryGroupContainer);
                //RemoveVisualChild(galleryGroupContainer);
                visualCollection.Remove(galleryGroupContainer);
            }
            galleryGroupContainers.Clear();

            // Gets filters
            string[] filter = Filter == null ? null : Filter.Split(',');

            Dictionary <string, GalleryGroupContainer> dictionary = new Dictionary <string, GalleryGroupContainer>();

            foreach (UIElement item in InternalChildren)
            {
                if (item == null)
                {
                    continue;
                }

                // Resolve group name
                string propertyValue;
                if (GroupByAdvanced == null)
                {
                    propertyValue = (ItemContainerGenerator == null)
                                        ? GetPropertyValueAsString(item)
                                        : GetPropertyValueAsString(ItemContainerGenerator.ItemFromContainer(item));
                }
                else
                {
                    propertyValue = (ItemContainerGenerator == null)
                                        ? GroupByAdvanced(item)
                                        : GroupByAdvanced(ItemContainerGenerator.ItemFromContainer(item));
                }
                if (propertyValue == null)
                {
                    propertyValue = "Undefined";
                }

                // Make invisible if it is not in filter (or is not grouped)
                if ((!IsGrouped) || (filter != null && !filter.Contains(propertyValue)))
                {
                    item.Measure(new Size(0, 0));
                    item.Arrange(new Rect(0, 0, 0, 0));
                }
                // Skip if it is not in filter
                if (filter != null && !filter.Contains(propertyValue))
                {
                    continue;
                }

                // To put all items in one group in case of IsGrouped = False
                if (!IsGrouped)
                {
                    propertyValue = "Undefined";
                }

                if (!dictionary.ContainsKey(propertyValue))
                {
                    GalleryGroupContainer galleryGroupContainer = new GalleryGroupContainer();
                    galleryGroupContainer.Header = propertyValue;
                    RibbonControl.Bind(this, galleryGroupContainer, "GroupStyle", GroupStyleProperty, BindingMode.OneWay);
                    RibbonControl.Bind(this, galleryGroupContainer, "Orientation", GalleryGroupContainer.OrientationProperty, BindingMode.OneWay);
                    RibbonControl.Bind(this, galleryGroupContainer, "ItemWidth", GalleryGroupContainer.ItemWidthProperty, BindingMode.OneWay);
                    RibbonControl.Bind(this, galleryGroupContainer, "ItemHeight", GalleryGroupContainer.ItemHeightProperty, BindingMode.OneWay);
                    RibbonControl.Bind(this, galleryGroupContainer, "MaxItemsInRow", GalleryGroupContainer.MaxItemsInRowProperty, BindingMode.OneWay);
                    RibbonControl.Bind(this, galleryGroupContainer, "MinItemsInRow", GalleryGroupContainer.MinItemsInRowProperty, BindingMode.OneWay);
                    dictionary.Add(propertyValue, galleryGroupContainer);
                    galleryGroupContainers.Add(galleryGroupContainer);

                    visualCollection.Add(galleryGroupContainer);
                }
                dictionary[propertyValue].Items.Add(new GalleryItemPlaceholder(item));
            }

            if (((!IsGrouped) || (GroupBy == null && GroupByAdvanced == null)) && galleryGroupContainers.Count != 0)
            {
                // Make it without headers
                galleryGroupContainers[0].IsHeadered = false;
            }

            InvalidateMeasure();
        }