Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Alt-key shortcuts in WPF/XAML

I have a XAML window with multiple TextBoxes, each with a corresponding TextBlock tag for a title. I would like to enable Alt-key shortcuts for this window (hold down the Alt key to show underlined letters in the TextBlock titles, type one of those letters and focus should change to the corresponding TextBox).

I've found out how to do a similar thing for menu items (place an underscore in the title for the menu), but how does one go about doing it for other items in a window in this case?

like image 395
DashRantic Avatar asked Nov 02 '09 15:11

DashRantic


Video Answer


1 Answers

Instead of using TextBlock, use the Label control. It has intrinsic support for associating a mnemonic with another control via it's Target property. To choose the character that will represent the alt+ you simply prefix it with an _ (underscore) in the Label's Content.

like image 91
Drew Marsh Avatar answered Oct 17 '22 02:10

Drew Marsh