473,549 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 48766
>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.Fo cusedElement="{ Binding ElementName=myT extBox}">
....
<TextBox Name="myTextBox " />
....
</Window>

Chris Jobson
Jun 27 '08 #2
<Window
...
FocusManager.Fo cusedElement="{ Binding ElementName=myT extBox}">
...
<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.F ocusedElement=" {Binding ElementName=myT extBox}">
...
<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
4945
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 immediately start typing without having to click in the textbox. I tried textBox.Focus(), textBox.SelectAll() with no success... The tabindex of the...
2
301
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 ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
4
6714
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 the focus after my app starts. Even if no other app is running, my app will not be activated until the user clicks on the window Thanks
1
2507
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 clientside, on form validation in javascript, I would like to set focus on to one of the tabs and set the focus to the control on that tab.
7
5846
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 Object, ByVal e As System.EventArgs)
2
1689
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
2564
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
2909
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 dropdown. Otherwise, the default behavior is fine. Thanks Andy
3
2460
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 single digit) like 801 or 1001 (I add an extra 1 to make sure it is unique). Then go through all your controls and check the tab indexes to make...
0
7959
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7473
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7810
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5369
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1061
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.