I have a WPF user control where I have multiple text boxes and and combo boxes. For easy use I want to provide shortcut keys to focus some main control.
Suppose if I press ALT + M it will focus on a text box named txtPatient
.
If I press ALT + B it will focus on a text box named txtRef
.
I am using MVVM as the design pattern.
How can I do this?
Sounds to me like basic accessibility (mnemonics), which is easy to obtain by adding labels to your controls like:
<Label Content="_Name" Target="{Binding ElementName=textBoxName}" />
<TextBox x:Name="textBoxName" />
Notice the "_N" - that means when the user presses ALT + N , textBoxName
will get focus.
Thomas Levesque answered this is a separate post here .
He mentions his own custom markup extension which allows for just this:
<UserControl.InputBindings>
<KeyBinding Modifiers="Control" Key="E" Command="{input:CommandBinding EditCommand}"/>
</UserControl.InputBindings>
Hope this helps :)
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.