RadRibbonGroup Collapsed when no visible children

2 posts, 0 answers
  1. Michel Cossette
    Michel Cossette avatar
    7 posts
    Member since:
    Feb 2010

    Posted 10 Apr 2018 Link to this post

    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.

  2. Martin
    Martin avatar
    126 posts

    Posted 13 Apr 2018 Link to this post

    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;
            group.Visibility = Visibility.Collapsed;
    <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.

    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.
Back to Top