SetRibbonSize() 공개 정적인 메소드

Sets SizeDefinition for element
public static SetRibbonSize ( DependencyObject element, RibbonControlSize value ) : void
element System.Windows.DependencyObject
value RibbonControlSize
리턴 void
예제 #1
0
        /// <summary>
        /// Handles size property changing
        /// </summary>
        /// <param name="previous">Previous value</param>
        /// <param name="current">Current value</param>
        public void OnSizePropertyChanged(RibbonControlSize previous, RibbonControlSize current)
        {
            foreach (var frameworkElement in actualChildren)
            {
                RibbonAttachedProperties.SetRibbonSize(frameworkElement, current);
            }

            rebuildVisualAndLogicalChildren = true;
            InvalidateMeasure();
        }
예제 #2
0
        /// <summary>
        /// Binds default properties of control to quick access element
        /// </summary>
        /// <param name="element">Toolbar item</param>
        /// <param name="source">Source item</param>
        public static void BindQuickAccessItem(FrameworkElement source, FrameworkElement element)
        {
            if (source is ICommandSource)
            {
                if (source is MenuItem)
                {
                    Bind(source, element, "CommandParameter", ButtonBase.CommandParameterProperty, BindingMode.OneWay);
                    Bind(source, element, "CommandTarget", MenuItem.CommandTargetProperty, BindingMode.OneWay);
                    Bind(source, element, "Command", MenuItem.CommandProperty, BindingMode.OneWay);
                }
                else
                {
                    Bind(source, element, "CommandParameter", ButtonBase.CommandParameterProperty, BindingMode.OneWay);
                    Bind(source, element, "CommandTarget", ButtonBase.CommandTargetProperty, BindingMode.OneWay);
                    Bind(source, element, "Command", ButtonBase.CommandProperty, BindingMode.OneWay);
                }
            }
            Bind(source, element, "ToolTip", ToolTipProperty, BindingMode.OneWay);

            Bind(source, element, "FontFamily", FontFamilyProperty, BindingMode.OneWay);
            Bind(source, element, "FontSize", FontSizeProperty, BindingMode.OneWay);
            Bind(source, element, "FontStretch", FontStretchProperty, BindingMode.OneWay);
            Bind(source, element, "FontStyle", FontStyleProperty, BindingMode.OneWay);
            Bind(source, element, "FontWeight", FontWeightProperty, BindingMode.OneWay);

            Bind(source, element, "Foreground", ForegroundProperty, BindingMode.OneWay);
            Bind(source, element, "IsEnabled", IsEnabledProperty, BindingMode.OneWay);
            Bind(source, element, "Opacity", OpacityProperty, BindingMode.OneWay);
            Bind(source, element, "SnapsToDevicePixels", SnapsToDevicePixelsProperty, BindingMode.OneWay);

            IRibbonControl sourceControl = source as IRibbonControl;

            if (sourceControl.Icon != null)
            {
                Visual iconVisual = sourceControl.Icon as Visual;
                if (iconVisual != null)
                {
                    Rectangle rect = new Rectangle();
                    rect.Width  = 16;
                    rect.Height = 16;
                    rect.Fill   = new VisualBrush(iconVisual);
                    (element as IRibbonControl).Icon = rect;
                }
                else
                {
                    Bind(source, element, "Icon", RibbonControl.IconProperty, BindingMode.OneWay);
                }
            }
            if (sourceControl.Header != null)
            {
                Bind(source, element, "Header", RibbonControl.HeaderProperty, BindingMode.OneWay);
            }

            RibbonAttachedProperties.SetRibbonSize(element, RibbonControlSize.Small);
        }
예제 #3
0
        /// <summary>
        /// Gets control which represents shortcut item.
        /// This item MUST be synchronized with the original
        /// and send command to original one control.
        /// </summary>
        /// <returns>Control which represents shortcut item</returns>
        public override FrameworkElement CreateQuickAccessItem()
        {
            SplitButton button = new SplitButton();

            button.Click += ((sender, e) => RaiseEvent(e));
            RibbonAttachedProperties.SetRibbonSize(button, RibbonControlSize.Small);
            button.CanAddButtonToQuickAccessToolBar = false;
            BindQuickAccessItem(button);
            BindQuickAccessItemDropDownEvents(button);
            button.DropDownOpened += OnQuickAccessOpened;
            return(button);
        }
예제 #4
0
        /// <summary>
        /// Gets control which represents shortcut item.
        /// This item MUST be synchronized with the original
        /// and send command to original one control.
        /// </summary>
        /// <returns>Control which represents shortcut item</returns>
        public virtual FrameworkElement CreateQuickAccessItem()
        {
            var button = new DropDownButton();

            RibbonAttachedProperties.SetRibbonSize(button, RibbonControlSize.Small);

            BindQuickAccessItem(button);
            RibbonControl.Bind(this, button, "DisplayMemberPath", DisplayMemberPathProperty, BindingMode.OneWay);
            RibbonControl.Bind(this, button, "GroupStyleSelector", GroupStyleSelectorProperty, BindingMode.OneWay);
            RibbonControl.Bind(this, button, "ItemContainerStyle", ItemContainerStyleProperty, BindingMode.OneWay);
            RibbonControl.Bind(this, button, "ItemsPanel", ItemsPanelProperty, BindingMode.OneWay);
            RibbonControl.Bind(this, button, "ItemStringFormat", ItemStringFormatProperty, BindingMode.OneWay);
            RibbonControl.Bind(this, button, "ItemTemplate", ItemTemplateProperty, BindingMode.OneWay);

            RibbonControl.Bind(this, button, "MaxDropDownHeight", MaxDropDownHeightProperty, BindingMode.OneWay);

            BindQuickAccessItemDropDownEvents(button);

            button.DropDownOpened += OnQuickAccessOpened;
            return(button);
        }
예제 #5
0
        /// <summary>
        /// Layout logic for the given layout definition
        /// </summary>
        /// <param name="layoutDefinition">Current layout definition</param>
        /// <param name="availableSize">Available or final size</param>
        /// <param name="measure">Pass true if measure required; pass false if arrange required</param>
        /// <param name="addchildren">Determines whether we have to add children to the logical and visual tree</param>
        /// <returns>Final size</returns>
        Size CustomLayout(RibbonToolBarLayoutDefinition layoutDefinition, Size availableSize, bool measure, bool addchildren)
        {
            bool   arrange         = !measure;
            double availableHeight = Double.IsPositiveInfinity(availableSize.Height) ? 0 : availableSize.Height;

            // Clear separator cahce
            if (addchildren)
            {
                separatorCache.Clear();
            }

            // Get the first control and measure, its height accepts as row height
            double rowHeight = GetRowHeight(layoutDefinition);


            // Calculate whitespace
            int    rowCountInColumn = Math.Min(layoutDefinition.RowCount, layoutDefinition.Rows.Count);
            double whitespace       = (availableHeight - ((double)rowCountInColumn * rowHeight)) / (double)(rowCountInColumn + 1);

            double y = 0;
            double x = 0;
            double currentRowBegin = 0;
            double currentMaxX     = 0;
            double maxy            = 0;

            for (int rowIndex = 0; rowIndex < layoutDefinition.Rows.Count; rowIndex++)
            {
                RibbonToolBarRow row = layoutDefinition.Rows[rowIndex];

                x = currentRowBegin;

                if (rowIndex % rowCountInColumn == 0)
                {
                    // Reset vars at new column
                    x = currentRowBegin = currentMaxX;
                    y = 0;

                    if (rowIndex != 0)
                    {
                        #region Add separator

                        Separator separator = null;
                        if (!separatorCache.TryGetValue(rowIndex, out separator))
                        {
                            separator       = new Separator();
                            separator.Style = SeparatorStyle;
                            separatorCache.Add(rowIndex, separator);
                        }
                        if (measure)
                        {
                            separator.Height = availableHeight - separator.Margin.Bottom - separator.Margin.Top;
                            separator.Measure(availableSize);
                        }
                        if (arrange)
                        {
                            separator.Arrange(new Rect(x, y,
                                                       separator.DesiredSize.Width,
                                                       separator.DesiredSize.Height));
                        }
                        x += separator.DesiredSize.Width;

                        if (addchildren)
                        {
                            // Add control in the children
                            AddVisualChild(separator);
                            AddLogicalChild(separator);
                            actualChildren.Add(separator);
                        }

                        #endregion
                    }
                }
                y += whitespace;


                // Measure & arrange new row
                for (int i = 0; i < row.Children.Count; i++)
                {
                    if (row.Children[i] is RibbonToolBarControlDefinition)
                    {
                        // Control Definition Case
                        RibbonToolBarControlDefinition controlDefinition =
                            (RibbonToolBarControlDefinition)row.Children[i];
                        FrameworkElement control = GetControl(controlDefinition);
                        if (control == null)
                        {
                            continue;
                        }

                        if (addchildren)
                        {
                            // Add control in the children
                            AddVisualChild(control);
                            AddLogicalChild(control);
                            actualChildren.Add(control);
                        }

                        if (measure)
                        {
                            // Apply Control Definition Properties
                            RibbonAttachedProperties.SetRibbonSize(control, RibbonAttachedProperties.GetRibbonSize(controlDefinition));
                            control.Width = controlDefinition.Width;
                            control.Measure(availableSize);
                        }
                        if (arrange)
                        {
                            control.Arrange(new Rect(x, y,
                                                     control.DesiredSize.Width,
                                                     control.DesiredSize.Height));
                        }

                        x += control.DesiredSize.Width;
                    }
                    if (row.Children[i] is RibbonToolBarControlGroupDefinition)
                    {
                        // Control Definition Case
                        RibbonToolBarControlGroupDefinition controlGroupDefinition =
                            (RibbonToolBarControlGroupDefinition)row.Children[i];

                        RibbonToolBarControlGroup control = GetControlGroup(controlGroupDefinition);

                        if (addchildren)
                        {
                            // Add control in the children
                            AddVisualChild(control);
                            AddLogicalChild(control);
                            actualChildren.Add(control);
                        }

                        if (measure)
                        {
                            // Apply Control Definition Properties
                            control.IsFirstInRow = (i == 0);
                            control.IsLastInRow  = (i == row.Children.Count - 1);
                            control.Measure(availableSize);
                        }
                        if (arrange)
                        {
                            control.Arrange(new Rect(x, y,
                                                     control.DesiredSize.Width,
                                                     control.DesiredSize.Height));
                        }

                        x += control.DesiredSize.Width;
                    }
                }

                y += rowHeight;
                if (currentMaxX < x)
                {
                    currentMaxX = x;
                }
                if (maxy < y)
                {
                    maxy = y;
                }
            }

            return(new Size(currentMaxX, maxy + whitespace));
        }
 public RibbonToolBarControlDefinition()
 {
     RibbonAttachedProperties.SetRibbonSize(this, RibbonControlSize.Small);
 }