开发者

Help on using short cut keys

I have a WPF user control where I have multiple text boxes and and combo bo开发者_如何学Pythonxes. 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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜