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
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.
I was further looking into this and in order to avoid the loops depending on your scneario you can also use the methods XamRibbon.FindToolByID() or FindGroupByID().
If I can assist you furhter on the matter, please do not hesitate to ask.