Bug: Contextual group header might appear with wrong size

2 posts, 1 answers
  1. BENN
    BENN avatar
    62 posts
    Member since:
    Dec 2011

    Posted 04 Feb 2016 Link to this post

    It happens if you add the contextual group in code, and it is set as active.

    The size of the Tab inside the group should also be larger then the size of the header. The result is at appeared in the image.


    Here is the code:

    Main window xaml:

    <telerik:RadRibbonWindow x:Class="ContextualTab_Bug.MainWindow"
            Title="MainWindow" Height="350" Width="525" WindowState="Maximized">
                <RowDefinition Height="Auto"/>
                <RowDefinition />
            <telerik:RadRibbonView telerik:StyleManager.Theme="Windows7" ApplicationButtonContent="Home" x:Name="ribbon">
                <telerik:RadRibbonTab Foreground="Black" Header="Edit" telerik:KeyTipService.AccessText="E">
                <telerik:RadRibbonTab Header="Controller" Foreground="Black" telerik:KeyTipService.AccessText="P" IsSelected="True">
                <telerik:RadRibbonTab Header="Tools" ToolTip="Tools" telerik:KeyTipService.AccessText="T">
                <telerik:RadRibbonTab Header="Help" telerik:KeyTipService.AccessText="S">
            <Button HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Click="Button_Click">Add Contextual Tabs</Button>



     code behind that demonstrates the problem:

       public partial class MainWindow : RadRibbonWindow
            bool tabWasAdded = false;
            public MainWindow()
            private void Button_Click(object sender, RoutedEventArgs e)
                if (!tabWasAdded)
                    RadRibbonContextualGroup telerikContextualTab = new RadRibbonContextualGroup()
                        Name = "ct",
                    telerikContextualTab.Header = "Alarm";
                    telerikContextualTab.IsActive = true;
                    telerikContextualTab.Color = Brushes.Red;
                    RadRibbonTab tab = new RadRibbonTab();
                    tab.Header = "Alarms";
                    tab.ContextualGroupName = "ct";
                    ribbon.Items.Insert(ribbon.Items.Count - 1, tab);
                    tabWasAdded = true;
                    ribbon.ContextualGroups[0].IsActive = !ribbon.ContextualGroups[0].IsActive;



    If you click the twice again, then the contextual tabs will become inactive and then active, and this time, it will appear correctly.

    It will also be drawn with the correct size, if you just resize the window.



    I have a workaround for this issue:

    Add the group with IsActive=false, and then Set the IsActive=true with BeginInvoke with priority Render and higher...

  2. Answer
    Martin Ivanov
    Martin Ivanov avatar
    1451 posts

    Posted 08 Feb 2016 Link to this post

    Hello Ben,

    Thank you for the detailed description and the sample code. It was really useful for reproducing the reported behavior.

    Actually, the observed behavior is expected. This is because the contextual groups of the ribbonview measure themselves based on the size of the grouped RadRibbonTabs. In your case, the group and the tab are added almost at the same time, and the tab is not yet measured. So, the contextual group decides that the tab's size is (0,0) and render itself so that it only fits its header. This is the reason why the group is smaller than the RadRibbonTab. 

    The workaround described in your reply works due couple of reasons.
    • A measure phase starts for the group each time it becomes visible or the layout of the ribbonview is updated.
    • The contextual group becomes visible in a dispatcher which action starts after the RadRibbonTab is measured.

    Basically, in order for a group to be sized as expected you will need to ensure that its tabs are measured before the group becomes visible.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top