This project is read-only.

RibbonGroupBox - FullSize Fill ??

Oct 31, 2010 at 3:23 PM

I need some help to create a single RibbonGroupBox which stretched over the whole window width and a control, i.e. ComboBox which then stretches in that RibbonGroupBox from left to right.

My customized RibbonGroupBox works, however, when I plug my customized ComboBox into it, then it downsizes correctly but when I increase the window width the right parts of the ComboBox disappear as if it is overpainted with the background brush. Any help would be highly appreciated, other solution proposals are welcomed as well.

BTW - I am using 2.0 preview and please don't tell me it is off GUI standard, I know.

Here the customized RibbonGroupBox which works nicely:

using System;
using System.Windows;

namespace FluentEx
{
    public class RibbonGroupBox : Fluent.RibbonGroupBox
    {
        private Window parentWindow;

        protected override Size MeasureOverride(Size constraint)
        {
            if (State == Fluent.RibbonGroupBoxState.Collapsed) 
                return base.MeasureOverride(constraint);

            if (parentWindow == null)
            {
                parentWindow = Window.GetWindow(this);
                parentWindow.SizeChanged += new SizeChangedEventHandler(parentWindow_SizeChanged);
            }
            
            return new Size(parentWindow.Width - 18, constraint.Height);
        }

        void parentWindow_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.InvalidateMeasure();
        }
    }
}

Now, when I put the following customized ComboBox into the customized RibbonGroupBox I get strange behaviour:

using System;
using System.Windows;
using System.Windows.Controls;

namespace FluentEx
{
    public class ComboBox : Fluent.ComboBox
    {
        private FluentEx.RibbonGroupBox parent;

        protected override Size MeasureOverride(Size constraint)
        {
            if (parent == null)
            {
                parent = (FluentEx.RibbonGroupBox)this.Parent;
                parent.SizeChanged += new SizeChangedEventHandler(parent_SizeChanged);
            }

            double w = GetOtherChildWidth();

            Size size = new Size(parent.DesiredSize.Width - w - 18, 22);

            return size;
        }

        void parent_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.InvalidateMeasure();
        }

        double GetOtherChildWidth()
        {
            double w = 0;
            for (int i = 0; i < parent.Items.Count; i++)
            {
                Control control = (Control)parent.Items[i];
                if (control != (Control)this &&
                    !double.IsNaN(control.Width))
                    w += control.Width;
            }
            return w;
        }
    }
}

The relevant Xaml looks like this:

<ribbon:RibbonTabItem Header="Test TabItem" >
	<ribbonex:RibbonGroupBox Header="Test GroupBox" >
		<ribbonex:ComboBox x:Name="Test" Margin="0,12,0,12" />
	</ribbonex:RibbonGroupBox>
</ribbon:RibbonTabItem>