[英]Selecting a specific menu item from a context menu
I am working on a C# WPF application. 我正在使用C#WPF应用程序。 I have a context menu appear on a textbook using Infragistics library.
我在使用Infragistics库的教科书上出现了一个上下文菜单。 I want to be able to use my keyboard to scroll through the options and select one of them (by pressing enter key).
我希望能够使用键盘滚动选项并选择其中一个(按Enter键)。 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.
当我滚动菜单项时,我可以看到它们在菜单上被选中,但是当用户按下Enter键时,我不知道如何在菜单项中获得文本(例如“ cp”,“ high”等)。 Doing something like xamMenu.Items.CurrentItem is always returning null.
诸如xamMenu.Items.CurrentItem之类的操作总是返回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 : 如果是后者:在视图模型中创建一个与列表项类型相同的附加属性SelectedItem:
<ComboBox
ItemsSource="{Binding MyViewModel.Items}"
SelectedItem="{Binding MyViewModel.SelectedItem}"
ToolTip="some tooltip"
/>
Then SelectedItem should take the right value. 然后SelectedItem应该采用正确的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.