This is a migrated thread and some comments may be shown as answers.

RadRibbonGroup fill space

1 Answer 102 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Maurício
Top achievements
Rank 1
Maurício asked on 01 Sep 2014, 07:18 PM
Hello

I would like to know how I could fill all empty space in a RadRibbonTab with a RadRibbonGroup.

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 02 Sep 2014, 10:38 AM
Hello MaurĂ­cio,

There is no out-of-the-box approach for expanding a ribbon group in all available space of its ribbon tab. However, you can achieve this with custom code. Basically you can create a custom groups panel that inherits the RibbonGroupsPanel and override its ArrangeOverride() method. 

public class CustomPanel : RibbonGroupsPanel
{
    private const double Padding = 5d;
    protected override Size ArrangeOverride(Size finalSize)
    {
        var size = base.ArrangeOverride(finalSize);
 
        var groups = this.Children.OfType<RadRibbonGroup>();
        double x = 0d;
        for (int i = 0; i < groups.Count(); i++)
        {
            var group = groups.ElementAt(i);
            double width = group.DesiredSize.Width;
            if (i == groups.Count()-1)
            {
                var ribbon = this.ParentOfType<RadRibbonView>();
                width = Math.Max(0, ribbon.ActualWidth - x - Padding);
                group.Arrange(new Rect(x, 0, width, finalSize.Height));
            }
            if (width > 0)
            {
                x += width + this.ItemSpacing;
            }
        }
 
        return finalSize;
    }      
}
Then set it as an ItemsPanel of the RadRibbonTabs.

<Window.Resources>
    <ItemsPanelTemplate x:Key="RadRibbonGroupPanelTemplate">
        <local:CustomPanel/>
    </ItemsPanelTemplate>
    <Style TargetType="telerik:RadRibbonTab">
        <Setter Property="ItemsPanel" Value="{StaticResource RadRibbonGroupPanelTemplate}" />
    </Style>
</Window.Resources>

I also attached a sample project demonstrating this approach. Please give it a try and let me know if it works for you.

Regards,
Martin
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
RibbonView and RibbonWindow
Asked by
Maurício
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or