Наследование: System.Windows.DependencyObject
Пример #1
0
        // Get the first control and measure, its height accepts as row height
        private double GetRowHeight(RibbonToolBarLayoutDefinition layoutDefinition)
        {
            const double defaultRowHeight = 0;

            foreach (var row in layoutDefinition.Rows)
            {
                foreach (var item in row.Children)
                {
                    var controlDefinition      = item as RibbonToolBarControlDefinition;
                    var controlGroupDefinition = item as RibbonToolBarControlGroupDefinition;
                    FrameworkElement control   = null;

                    if (controlDefinition != null)
                    {
                        control = this.GetControl(controlDefinition);
                    }
                    else if (controlGroupDefinition != null)
                    {
                        control = this.GetControlGroup(controlGroupDefinition);
                    }

                    if (control is null)
                    {
                        return(defaultRowHeight);
                    }

                    control.Measure(SizeConstants.Infinite);

                    return(control.DesiredSize.Height);
                }
            }

            return(defaultRowHeight);
        }
Пример #2
0
        // Get the first control and measure, its height accepts as row height
        double GetRowHeight(RibbonToolBarLayoutDefinition layoutDefinition)
        {
            const double defaultRowHeight = 0;

            foreach (RibbonToolBarRow row in layoutDefinition.Rows)
            {
                foreach (DependencyObject item in row.Children)
                {
                    RibbonToolBarControlDefinition      controlDefinition      = item as RibbonToolBarControlDefinition;
                    RibbonToolBarControlGroupDefinition controlGroupDefinition = item as RibbonToolBarControlGroupDefinition;
                    FrameworkElement control = null;
                    if (controlDefinition != null)
                    {
                        control = GetControl(controlDefinition);
                    }
                    else if (controlGroupDefinition != null)
                    {
                        control = GetControlGroup(controlGroupDefinition);
                    }

                    if (control == null)
                    {
                        return(defaultRowHeight);
                    }
                    control.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                    return(control.DesiredSize.Height);
                }
            }
            return(defaultRowHeight);
        }
Пример #3
0
        /// <summary>
        /// When overridden in a derived class, positions child elements and determines
        /// a size for a System.Windows.FrameworkElement derived class.
        /// </summary>
        /// <param name="finalSize">The final area within the parent that this
        /// element should use to arrange itself and its children.</param>
        /// <returns>The actual size used.</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            RibbonToolBarLayoutDefinition layoutDefinition = GetCurrentLayoutDefinition();

            if (layoutDefinition == null)
            {
                return(WrapPanelLayuot(finalSize, false));
            }
            return(CustomLayout(layoutDefinition, finalSize, false, false));
        }
Пример #4
0
        /// <summary>
        /// Measures all of the RibbonGroupBox, and resize them appropriately
        /// to fit within the available room
        /// </summary>
        /// <param name="availableSize">The available size that
        /// this element can give to child elements.</param>
        /// <returns>The size that the panel determines it needs during
        /// layout, based on its calculations of child element sizes.
        /// </returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            RibbonToolBarLayoutDefinition layoutDefinition = GetCurrentLayoutDefinition();

            // Rebuilding actual children (visual & logical)
            if (rebuildVisualAndLogicalChildren)
            {
                // Clear previous children
                foreach (FrameworkElement child in actualChildren)
                {
                    RibbonToolBarControlGroup controlGroup = child as RibbonToolBarControlGroup;
                    if (controlGroup != null)
                    {
                        controlGroup.Items.Clear();
                    }
                    RemoveVisualChild(child);
                    RemoveLogicalChild(child);
                }
                actualChildren.Clear();
                cachedControlGroups.Clear();
            }

            if (layoutDefinition == null)
            {
                if (rebuildVisualAndLogicalChildren)
                {
                    // If default layout is used add all children
                    foreach (FrameworkElement child in Children)
                    {
                        actualChildren.Add(child);
                        AddVisualChild(child);
                        AddLogicalChild(child);
                    }
                    rebuildVisualAndLogicalChildren = false;
                }
                return(WrapPanelLayuot(availableSize, true));
            }
            else
            {
                Size result = CustomLayout(layoutDefinition, availableSize, true, rebuildVisualAndLogicalChildren);
                rebuildVisualAndLogicalChildren = false;
                return(result);
            }
        }
Пример #5
0
        // Determines whether the element is children to RibbonToolBar
        static bool IsWithinRibbonToolbarInTwoLine(DependencyObject element)
        {
            UIElement     parent        = LogicalTreeHelper.GetParent(element) as UIElement;
            RibbonToolBar ribbonToolBar = parent as RibbonToolBar;

            if (ribbonToolBar != null)
            {
                RibbonToolBarLayoutDefinition definition = ribbonToolBar.GetCurrentLayoutDefinition();
                if (definition == null)
                {
                    return(false);
                }
                if (definition.RowCount == 2 || definition.Rows.Count == 2)
                {
                    return(true);
                }
                return(false);
            }
            if (parent == null)
            {
                return(false);
            }
            return(IsWithinRibbonToolbarInTwoLine(parent));
        }
Пример #6
0
        // Get the first control and measure, its height accepts as row height
        double GetRowHeight(RibbonToolBarLayoutDefinition layoutDefinition)
        {
            const double defaultRowHeight = 0;
            foreach (RibbonToolBarRow row in layoutDefinition.Rows)
            {
                foreach (DependencyObject item in row.Children)
                {
                    RibbonToolBarControlDefinition controlDefinition = item as RibbonToolBarControlDefinition;
                    RibbonToolBarControlGroupDefinition controlGroupDefinition = item as RibbonToolBarControlGroupDefinition;
                    FrameworkElement control = null;
                    if (controlDefinition != null) control = this.GetControl(controlDefinition);
                    else if (controlGroupDefinition != null)
                        control = this.GetControlGroup(controlGroupDefinition);

                    if (control == null) return defaultRowHeight;
                    control.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                    return control.DesiredSize.Height;
                }
            }
            return defaultRowHeight;
        }
Пример #7
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)
                this.separatorCache.Clear();

            // Get the first control and measure, its height accepts as row height
            double rowHeight = this.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 (!this.separatorCache.TryGetValue(rowIndex, out separator))
                        {
                            separator = new Separator();
                            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(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 = this.GetControl(controlDefinition);
                        if (control == 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(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 = this.GetControlGroup(controlGroupDefinition);
                        
                        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);
        }
Пример #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>
        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));
        }
Пример #9
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));
        }