An alternative solution is to put the text of your menu in a TextBox with the configured properties.
If you build MenuItem code in code, it will look like this:
var menuItem = new MenuItem(); var menuHeader = new Textbox(); menuHeader.Text = "your_text_here"; menuHeader.IsReadOnly = true; menuHeader.Background = Brushes.Transparent; menuHeader.BorderThickness = new Thickness(0); menuItem.Header = menuHeader; menuItem.ToolTip = "your detailed tooltip here"; menuItem.Click += YourEventHandlerHere; yourMenu.Items.Add(menuItem);
If your menu is in XAML and this is just dynamic text, it will look like this:
<MenuItem Name="menuDynamic" Click="menuDynamic_Click"> <MenuItem.Header> <TextBox Name="dynamicMenu" Text="With_Underscore" IsReadOnly="True" Background="Transparent" BorderThickness="0" /> </MenuItem.Header> </MenuItem>
Then your code could dynamically set dynamicMenu.Text = "what_ever"; , when it is necessary.
source share