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

Bug: Contextual group header might appear with wrong size

1 Answer 57 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
BENN
Top achievements
Rank 1
BENN asked on 04 Feb 2016, 12:06 PM

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">
     
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition />
        </Grid.RowDefinitions>
 
        <telerik:RadRibbonView telerik:StyleManager.Theme="Windows7" ApplicationButtonContent="Home" x:Name="ribbon">
            <telerik:RadRibbonTab Foreground="Black" Header="Edit" telerik:KeyTipService.AccessText="E">
            </telerik:RadRibbonTab>
 
            <telerik:RadRibbonTab Header="Controller" Foreground="Black" telerik:KeyTipService.AccessText="P" IsSelected="True">
            </telerik:RadRibbonTab>
 
            <telerik:RadRibbonTab Header="Tools" ToolTip="Tools" telerik:KeyTipService.AccessText="T">
            </telerik:RadRibbonTab>
 
            <telerik:RadRibbonTab Header="Help" telerik:KeyTipService.AccessText="S">
            </telerik:RadRibbonTab>
        </telerik:RadRibbonView>
         
        <Button HorizontalAlignment="Center" VerticalAlignment="Center" Grid.Row="1" Click="Button_Click">Add Contextual Tabs</Button>
    </Grid>
</telerik:RadRibbonWindow>

 

 

 code behind that demonstrates the problem:

   public partial class MainWindow : RadRibbonWindow
    {
        bool tabWasAdded = false;
        public MainWindow()
        {
            InitializeComponent();
        }
 
        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.ContextualGroups.Add(telerikContextualTab);
 
                ribbon.Items.Insert(ribbon.Items.Count - 1, tab);
                tabWasAdded = true;
            }
            else
            {
                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...

1 Answer, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 08 Feb 2016, 10:54 AM
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.

Regards,
Martin
Telerik
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
Tags
RibbonView and RibbonWindow
Asked by
BENN
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or