473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 48753
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: zdavid | last post by:
Hi, I have a dialog box with a multiline textbox and three buttons. The obvious thing I'm suffering with is how to give focus to the textbox, so that when the dialogbox pops up, the user could...
2
by: tfs | last post by:
How do I set a field on my screen to get focus when the page opens? Thanks, Tom Posted Via Usenet.com Premium Usenet Newsgroup Services...
4
by: Benoit Martin | last post by:
How can I make sure that my Windows application will have the focus at startup? Currently, if there is an Explorer window open when I launch my app for example, the Explorer window will still have...
1
by: Praveena.Alapati | last post by:
Hi, There is a tab control on a page with multiple tabs and handful of controls in each tab. The way it's rendered in html (like grid etc..) is in table format in tablerows and cells. On...
7
by: jonathandrott | last post by:
hi, I'm trying to update a label with the text in a textbox as the user types in the information. something like this is not working: Protected Sub TextBox1_TextChanged(ByVal sender As...
2
by: venkatarp | last post by:
Hi , I am facing one different problem. I have dropdown and textbox. After i selected drop down textbox should focus. But its disabled and not focussing......
0
by: =?Utf-8?B?Q2hha2thcmFkZWVw?= | last post by:
Hi All, I have a public property, private String _Name; public String Name { get{return _Name;} set{_Name=value;} }
2
by: Andy | last post by:
Hi, I have a combobox, and the template for each item in the combo contains two text boxes. If the textbox is readonly, I'd like clicking on the textbox to select the item and close to...
3
by: Rich P | last post by:
One thing I have noticed with .Net is that various controls can have the same tab index and the app still compiles. I would set the tab index of your splitter to some large number (larger than a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.