Beispiel #1
0
        // Handles visibility changed
        private static void OnVisibilityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RibbonGroupBox box = (d as RibbonGroupBox);

            box.ClearCache();
        }
Beispiel #2
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 groups container determines it needs during
        /// layout, based on its calculations of child element sizes.
        /// </returns>
        protected override Size MeasureOverride(Size availableSize)
        {
            Size infinitySize = new Size(Double.PositiveInfinity, availableSize.Height);
            Size desiredSize  = GetChildrenDesiredSizeIntermediate();

            if (reduceOrder.Length == 0)
            {
                VerifyScrollData(availableSize.Width, desiredSize.Width);
                return(desiredSize);
            }

            // If we have more available space - try to expand groups
            while (desiredSize.Width <= availableSize.Width)
            {
                bool hasMoreVariants = reduceOrderIndex < reduceOrder.Length - 1;
                if (!hasMoreVariants)
                {
                    break;
                }

                // Increase size of another item
                reduceOrderIndex++;
                IncreaseGroupBoxSize(reduceOrder[reduceOrderIndex]);

                desiredSize = GetChildrenDesiredSizeIntermediate();
            }

            // If not enough space - go to next variant
            while (desiredSize.Width > availableSize.Width)
            {
                bool hasMoreVariants = reduceOrderIndex >= 0;
                if (!hasMoreVariants)
                {
                    break;
                }

                // Decrease size of another item
                DecreaseGroupBoxSize(reduceOrder[reduceOrderIndex]);
                reduceOrderIndex--;

                desiredSize = GetChildrenDesiredSizeIntermediate();
            }

            // Set find values
            foreach (object item in InternalChildren)
            {
                RibbonGroupBox groupBox = item as RibbonGroupBox;
                if (groupBox == null)
                {
                    continue;
                }

                if ((groupBox.State != groupBox.StateIntermediate) ||
                    (groupBox.Scale != groupBox.ScaleIntermediate))
                {
                    groupBox.SuppressCacheReseting = true;
                    groupBox.State = groupBox.StateIntermediate;
                    groupBox.Scale = groupBox.ScaleIntermediate;
                    groupBox.InvalidateLayout();
                    groupBox.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                    groupBox.SuppressCacheReseting = false;
                }

                // Something wrong with cache?
                if (groupBox.DesiredSizeIntermediate != groupBox.DesiredSize)
                {
                    // Reset cache and reinvoke masure
                    groupBox.ClearCache();
                    return(MeasureOverride(availableSize));
                }
            }

            VerifyScrollData(availableSize.Width, desiredSize.Width);
            return(desiredSize);
        }