I already have the following:
var myContextMenu = new System.Windows.Controls.ContextMenu();
var exitItem = new MenuItem();
exitItem.Header = "E_xit";
exitItem.Item.Click += new RoutedEventHandler(new System.EventHandler(ExitProgram));
myContextMenu.Items.Add(exitItem);
This causes my context menu to display the Exit menu item, with an underlined "x". However, pressing x does nothing. Clicking the menu item works fine.
How can I associate an event with the x key? Please note that this has to be done programmatically in my context. I cannot compose this solution in the XAML in front.