Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
760
MenuTool Visibility
posted

Hi,

Is there any way how to change visibility of MenuTool that contains GalleryTool?  I need to dynamically hide MenuTool if  GalleryTool Items collection is empty.

Thanks

Parents
  • 17559
    posted

    Hello gxclarke,

     

    I was looking into your requirements and in order to hide the empty element I can suggest you remove the MenuTool form the Tools collection of the XamRibbonGroup that it belongs. Depending on your scenario you can use different events and approaches to get the XamRibbonGroup collection and to check if the containing GalleryTool is empty. For example you can try handle the Loaded event of the XamRibbonTabItem and iterate between all of the elements:

    XamRibbonTabItem tabItem=(sender as XamRibbonTabItem);

                for (int i = 0; i < tabItem.Groups.Count; i++)

                    for (int j = 0; j < (tabItem.Groups[i] as XamRibbonGroup).Tools.Count; j++)

                        if ((tabItem.Groups[i] as XamRibbonGroup).Tools[j] is MenuTool)

                        {

                            MenuTool mt= (tabItem.Groups[i] as XamRibbonGroup).Tools[j] as MenuTool;

                            foreach (RibbonToolBase tool in mt.Items)

                            {

                                GalleryTool gt = tool as GalleryTool;

                                if (gt!=null && (gt as GalleryTool).Groups.Count == 0)

                                    (tabItem.Groups[i] as XamRibbonGroup).Tools.Remove(mt);

                            }

                        }

     Please let me know if I misunderstood you in any way or if you have any additional questions on the matter.

Reply Children