Hello. Today I had to get mnemonic to work. Mnemonic is the ability to navigate to a control using a key stroke combination. One of the most common mnemonics is Alt + F. Alt + F usually navigates to the File drop down menu in any Window, and most everyone is familiar with this mnemonic.

In WPF, to get mnemonics, you pretty much just put an underscore in front of a word. For example, for Alt + F, you would enter: _File

Well, in WPF I needed to do the Label, TextBox matching, so that the mnemonics is on a Label but the key strokes navigate the keyboard focus to the TextBox.

Lets say you have a simple form in WPF like this:

The XAML to make these work together using mnemonics is simple. The important property is Target.

Notice line 5 first. Here I am setting the FocusManager.FocusedElement to the first text box so that you can immediately type in the first field when arriving at the window.

Notice the use of AccessText instead of TextBlock (lines 15, 19). You don’t have to do it this way. You could have just set the Content property on the label. You don’t need the AccessText at all unless you want to wrap. If you want to wrap, you have to do it this way.

Notice the use of Target (lines 18,14) and how it is bound to the element that should receive focus when the mnemonic keys are pressed.

Hope this helps you.

Like this:

LikeLoading...

Related

5 Comments

Another comment. If you do want to use an image and keep it in your soolitun folder and then just reference it from wherever the application is, simply use ./ for the path on your ImageSource attribute. Example:

My other blogs

Entries (RSS) and Comments (RSS). Copyright ® Rhyous.com Linking to content on this site is allowed without permission and as many as ten lines of any article can be used along with such link. Any other use of the content is allowed only by permission of Rhyous.com.