471,853 Members | 1,254 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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 48604
>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
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.