WPF Controls TabIndex: Moving to the First Input Control
Posted
Thursday, October 25, 2007 1:07 AM
by
cromwellryan
Here's one of those real-world situations that no one bothers to demo. If you are building a form or have some sort of input your gathering from the user, you'll likely want the first input control Focused initially. You have a few ways to do this (in ascending order of recommendation):
- Call Focus() on the first control explicitly (meh).
- Iterate the controls collection and find the lowest TabIndex (terrible code smell).
- Do the following in the Load event:
this.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));