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

RadRibbonGroup Collapsed when no visible children

1 Answer 219 Views
RibbonView and RibbonWindow
This is a migrated thread and some comments may be shown as answers.
Michel Cossette
Top achievements
Rank 1
Michel Cossette asked on 10 Apr 2018, 08:47 PM

Hi all,

In our app, which uses a RibbonWindow and RibbonView, we have some RibbonTabs that are contextual to the currently open workspace, buttons on these tabs  are visible only to the users that have the specific security rights for the command it's bound to. These contextual RibbonTabs and their content are defined in the MainWindow xaml file, each button's visibility is databound via a converter to a CanDoThisOrThat bool property of the current workspace, the button's Command is also bound to an ICommand of the current Workspace. When a workspace is initialized, it reads the security rights of the user and set's the CanDoThisOrThat property which is then used to set the Visibility of the button.

So, our issue now it that depending on the security rights of the user, some RibbonGroups are left empty which looks kind of weird. I have tried some hacky code like hooking-up to the GotFocus event of the RibbonTab and then looping thru its Items to check for IsVisible. if none is found to be visible, the RibbonGroup's visibility is set to Collapsed. This kind of works but some RibbonTab's GotFocus event handler is never called and thus the empty groups are visible.

So my question is: Is there a way to collapse a RibbonGroup when it has no visible children?

Thank you.

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 13 Apr 2018, 11:50 AM
Hi Michel ,

A similar approach could be used, but instead on got focus, it might be more convenient to use OnLoaded for the RadRibbonGroup. I have tried this and it seems to work. That would be in the case when these properties are set before the Loaded event of the group. You can give the following approach a try:
private void RadRibbonGroup_Loaded(object sender, RoutedEventArgs e)
{
    var group = sender as RadRibbonGroup;
    if (group != null)
    {
        foreach (Control item in group.Items)
        {
            if (item.Visibility == Visibility.Visible)
            {
                group.Visibility = Visibility.Visible;
                return;
            }
        }
        group.Visibility = Visibility.Collapsed;
        return;
    }
}
<telerik:RadRibbonGroup Header="..." Loaded="RadRibbonGroup_Loaded"> ...

I hope that this would work for your case. If it does not or if you have any other questions, please do not hesitate to contact us further.

Regards,
Martin
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
RibbonView and RibbonWindow
Asked by
Michel Cossette
Top achievements
Rank 1
Answers by
Martin
Telerik team
Share this question
or