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
1360
Finding sub menu item programmatically
posted

When using a context menu I want to modify an item in the menu list so I am trying this:

private void ribbonContextMenu_Opening(object sender, OpeningEventArgs e)
{
    XamContextMenu ribbonContextMenu = sender as XamContextMenu;
    XamMenuItem minimizeMenu = ribbonContextMenu.FindName("minimizeMenu") as XamMenuItem;
    if (MyRibbon.IsMinimized)
        minimizeMenu.Header = "Expand Ribbon";
    else
        minimizeMenu.Header = "Minimize Ribbon";
}

However it fails to find the menuitem. What do I need to do here? It is quite annoying I cant just use the variable name as defined in the XAML but that is also NULL and I have read elsewhere on this forum that this is deliberate.

Please advise.

Doug Rees

Parents
No Data
Reply
  • 1360
    posted

    This seems to work, but is it the best approach?

    XamMenuItem minimizeMenu = ribbonContextMenu.Items.Cast<XamMenuItem>().FirstOrDefault(item => item.Name == "minimizeMenu");

Children
No Data