Esempio n. 1
0
        /// <inheritdoc />
        public void OnSizePropertyChanged(RibbonControlSize previous, RibbonControlSize current)
        {
            foreach (var frameworkElement in this.actualChildren)
            {
                RibbonProperties.SetSize(frameworkElement, current);
            }

            this.rebuildVisualAndLogicalChildren = true;
            this.InvalidateMeasure();
        }
Esempio n. 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);
            }

            RibbonProperties.SetSize(element, RibbonControlSize.Small);
        }
Esempio n. 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()
        {
            var buttonForQAT = new SplitButton();

            buttonForQAT.Click += (sender, e) => this.RaiseEvent(e);
            RibbonProperties.SetSize(buttonForQAT, RibbonControlSize.Small);
            buttonForQAT.CanAddButtonToQuickAccessToolBar = false;
            this.BindQuickAccessItem(buttonForQAT);
            this.BindQuickAccessItemDropDownEvents(buttonForQAT);
            buttonForQAT.DropDownOpened += this.OnQuickAccessOpened;
            this.quickAccessButton       = buttonForQAT;
            return(buttonForQAT);
        }
Esempio n. 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 override FrameworkElement CreateQuickAccessItem()
        {
            SplitButton button = new SplitButton();

            button.Click += ((sender, e) => RaiseEvent(e));
            RibbonProperties.SetSize(button, RibbonControlSize.Small);
            button.CanAddButtonToQuickAccessToolBar = false;
            BindQuickAccessItem(button);
            BindQuickAccessItemDropDownEvents(button);
            button.DropDownOpened  += OnQuickAccessOpened;
            this._quickAccessButton = button;
            return(button);
        }
Esempio n. 5
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();

            RibbonProperties.SetSize(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);
        }
 public RibbonToolBarControlDefinition()
 {
     RibbonProperties.SetSize(this, RibbonControlSize.Small);
 }
Esempio n. 7
0
        /// <summary>
        /// Binds default properties of control to quick access element
        /// </summary>
        /// <param name="source">Source item</param>
        /// <param name="element">Toolbar item</param>
        public static void BindQuickAccessItem(FrameworkElement source, FrameworkElement element)
        {
            Bind(source, element, nameof(source.DataContext), DataContextProperty, BindingMode.OneWay);

            if (source is ICommandSource)
            {
                if (source is MenuItem)
                {
                    Bind(source, element, nameof(ICommandSource.CommandParameter), System.Windows.Controls.MenuItem.CommandParameterProperty, BindingMode.OneWay);
                    Bind(source, element, nameof(ICommandSource.CommandTarget), System.Windows.Controls.MenuItem.CommandTargetProperty, BindingMode.OneWay);
                    Bind(source, element, nameof(ICommandSource.Command), System.Windows.Controls.MenuItem.CommandProperty, BindingMode.OneWay);
                }
                else
                {
                    Bind(source, element, nameof(ICommandSource.CommandParameter), ButtonBase.CommandParameterProperty, BindingMode.OneWay);
                    Bind(source, element, nameof(ICommandSource.CommandTarget), ButtonBase.CommandTargetProperty, BindingMode.OneWay);
                    Bind(source, element, nameof(ICommandSource.Command), ButtonBase.CommandProperty, BindingMode.OneWay);
                }
            }

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

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

            Bind(source, element, new PropertyPath(FocusManager.IsFocusScopeProperty), FocusManager.IsFocusScopeProperty, BindingMode.OneWay);

            if (source is IHeaderedControl headeredControl)
            {
                if (headeredControl is HeaderedItemsControl)
                {
                    Bind(source, element, nameof(HeaderedItemsControl.Header), HeaderedItemsControl.HeaderProperty, BindingMode.OneWay);
                    Bind(source, element, nameof(HeaderedItemsControl.HeaderStringFormat), HeaderedItemsControl.HeaderStringFormatProperty, BindingMode.OneWay);
                    Bind(source, element, nameof(HeaderedItemsControl.HeaderTemplate), HeaderedItemsControl.HeaderTemplateProperty, BindingMode.OneWay);
                    Bind(source, element, nameof(HeaderedItemsControl.HeaderTemplateSelector), HeaderedItemsControl.HeaderTemplateSelectorProperty, BindingMode.OneWay);
                }
                else
                {
                    Bind(source, element, nameof(IHeaderedControl.Header), HeaderProperty, BindingMode.OneWay);
                }

                if (source.ToolTip != null ||
                    BindingOperations.IsDataBound(source, ToolTipProperty))
                {
                    Bind(source, element, nameof(ToolTip), ToolTipProperty, BindingMode.OneWay);
                }
                else
                {
                    Bind(source, element, nameof(IHeaderedControl.Header), ToolTipProperty, BindingMode.OneWay);
                }
            }

            var ribbonControl = source as IRibbonControl;

            if (ribbonControl?.Icon != null)
            {
                if (ribbonControl.Icon is Visual iconVisual)
                {
                    var rect = new Rectangle
                    {
                        Width  = 16,
                        Height = 16,
                        Fill   = new VisualBrush(iconVisual)
                    };
                    ((IRibbonControl)element).Icon = rect;
                }
                else
                {
                    Bind(source, element, nameof(IRibbonControl.Icon), IconProperty, BindingMode.OneWay);
                }
            }

            RibbonProperties.SetSize(element, RibbonControlSize.Small);
        }
Esempio n. 8
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>
        private Size CustomLayout(RibbonToolBarLayoutDefinition layoutDefinition, Size availableSize, bool measure, bool addchildren)
        {
            var arrange         = !measure;
            var availableHeight = double.IsPositiveInfinity(availableSize.Height)
                ? 0
                : availableSize.Height;

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

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

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

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

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

                var x = currentRowBegin;

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

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

                        if (this.separatorCache.TryGetValue(rowIndex, out var separator) == false)
                        {
                            separator = new Separator
                            {
                                Style = this.SeparatorStyle
                            };
                            this.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
                            this.AddVisualChild(separator);
                            this.AddLogicalChild(separator);
                            this.actualChildren.Add(separator);
                        }

                        #endregion
                    }
                }

                y += whitespace;

                // Measure & arrange new row
                for (var i = 0; i < row.Children.Count; i++)
                {
                    // Control Definition Case
                    if (row.Children[i] is RibbonToolBarControlDefinition ribbonToolBarControlDefinition)
                    {
                        var control = this.GetControl(ribbonToolBarControlDefinition);

                        if (control is null)
                        {
                            continue;
                        }

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

                        if (measure)
                        {
                            // Apply Control Definition Properties
                            RibbonProperties.SetSize(control, RibbonProperties.GetSize(ribbonToolBarControlDefinition));
                            control.Width = ribbonToolBarControlDefinition.Width;
                            control.Measure(availableSize);
                        }

                        if (arrange)
                        {
                            control.Arrange(new Rect(x, y, control.DesiredSize.Width, control.DesiredSize.Height));
                        }

                        x += control.DesiredSize.Width;
                    }

                    // Control Group Definition Case
                    if (row.Children[i] is RibbonToolBarControlGroupDefinition ribbonToolBarControlGroupDefinition)
                    {
                        var control = this.GetControlGroup(ribbonToolBarControlGroupDefinition);

                        if (addchildren)
                        {
                            // Add control in the children
                            this.AddVisualChild(control);
                            this.AddLogicalChild(control);
                            this.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));
        }