Question

I am trying to populate my ConextMenu in code. I am adding some MenuItems in it. A MenuItem contains a string and event. So problem I am facing is that if the string contains underscore (_) then menu treats it as alt key. So in context menu I see character underlined which is after underscore.

e.g. MenuItem.Header = "Some Command_With"
Output = "Some CommandWith" (Where W of With is underlined)

Here is the code.

var menuName = Some String Generated on run time;
var contextMenu = GetContextMenu();
var menuItem = new MenuItem { Header = menuName };
contextMenu.Items.Add(menuItem);

Someone told me that I can set MenuItem template. But I am not sure how it can be done.

Was it helpful?

Solution

Use a double underscore, that will be treated like a single underscore.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top