469,287 Members | 2,748 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

WPF: how to set focus to a textbox at startup

I have a wpf window that contains a couple of text boxes. I want a certain
one of these to have focus at startup. IsFocused is read-only; I've set the
tabstop to 0; at startup, the focus is somewhere on the form (no visible
sign of what it might be). How do I do this very, very simple thing?

Jun 27 '08 #1
3 48320
>I have a wpf window that contains a couple of text boxes. I want a certain
>one of these to have focus at startup. IsFocused is read-only; I've set
the tabstop to 0; at startup, the focus is somewhere on the form (no
visible sign of what it might be). How do I do this very, very simple
thing?
<Window
....
FocusManager.FocusedElement="{Binding ElementName=myTextBox}">
....
<TextBox Name="myTextBox" />
....
</Window>

Chris Jobson
Jun 27 '08 #2
<Window
...
FocusManager.FocusedElement="{Binding ElementName=myTextBox}">
...
<TextBox Name="myTextBox" />
...
</Window>
Chris I'll try that. But isn't there a way to control this through the code
behind? What if I want to focus different controls depending on what the
user does?

Jeremy

Jun 27 '08 #3
><Window
>...
FocusManager.FocusedElement="{Binding ElementName=myTextBox}">
...
<TextBox Name="myTextBox" />
...
</Window>

Chris I'll try that. But isn't there a way to control this through the
code behind? What if I want to focus different controls depending on what
the user does?
Even easier!
myTextBox.Focus();
If you want to decide which control to give focus to when the form first
appears, put the code in the Loaded event.

Regards
Chris
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by zdavid | last post: by
4 posts views Thread by Benoit Martin | last post: by
1 post views Thread by Praveena.Alapati | last post: by
7 posts views Thread by jonathandrott | last post: by
reply views Thread by =?Utf-8?B?Q2hha2thcmFkZWVw?= | last post: by
2 posts views Thread by Andy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.