4

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.

fhnaseer
  • 7,159
  • 16
  • 60
  • 112
  • You can try the following http://stackoverflow.com/questions/40733/disable-wpf-label-accelerator-key-text-underscore-is-missing – Josh Anderson Feb 12 '14 at 07:35

1 Answers1

6

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

Christian Sauer
  • 10,351
  • 10
  • 53
  • 85