XAML ALT+letter to focus textbox

If you want the user to be able to focus a specific field with an ALT+Key – eg. ALT+F, you can do it the following way:

<Label Target="{Binding ElementName=Username}">Enter _Username:</Label>
<TextBox
Name="UserName"
Text="{Binding Username, Mode=TwoWay, UpdateSourceTrigger=LostFocus}">
</TextBox>
  • Target of Label associates it with the TextBox.
  • Underscore _Before a letter makes it accessible via the ALT+Key

If you are from the Web World, you are used to associating labels with inputs via the ID-attribute. Target looks similar.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *