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
This seems to work, but is it the best approach?
XamMenuItem minimizeMenu = ribbonContextMenu.Items.Cast<XamMenuItem>().FirstOrDefault(item => item.Name == "minimizeMenu");