Reputation: 1575
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?
Upvotes: 1
Views: 342
Reputation: 511
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.
Upvotes: 2
Reputation: 744
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 :)
Upvotes: 1