简体   繁体   中英

Selecting a specific menu item from a context menu

I am working on a C# WPF application. I have a context menu appear on a textbook using Infragistics library. I want to be able to use my keyboard to scroll through the options and select one of them (by pressing enter key). I can see items being selected on the menu when I scroll through them but I don't know how to get the text in the menu item (like "cp", "high" etc.) when the user hits enter. Doing something like xamMenu.Items.CurrentItem is always returning null.

Do you have code behind, or are the list items bound to a property in your viewmodel?

If the latter: create an additional property SelectedItem of the same type that your list items are, and in the viewmodel :

<ComboBox 
 ItemsSource="{Binding MyViewModel.Items}"
 SelectedItem="{Binding MyViewModel.SelectedItem}"
 ToolTip="some tooltip" 
/>

Then SelectedItem should take the right value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM