Mnemonic Keys in WPF

Mnemonic keys are keys that when pressed in combination with the ALT key move the focus to the control they are assigned to.

Labels in WPF have a built in support for mnemonic keys.

A mnemonic key can be specified by using the underscore symbol ( _ ) in front of the key you wish to assign. At runtime, you will notice that the key will appear underlined when the ALT key will be pressed.

Here is an example in XAML:



In this example, we have designated to Label1 a TextBox named TextBox1 and when the ALT+S keys will be pressed in combination, the textbox will receive focus.

No comments:

Post a Comment