Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - set focus on a textfield on application startup

 
 
Old 03-23-2006   #1 (permalink)
Bart van der Heijden


 
 

set focus on a textfield on application startup

Hi,

I want to set the focus on my textfield when the application starts, but i
don't know how to do this.

I tried:
txtIdentifier.Focus(); in the constructor of the codebehind of the xaml
window code, but it seems that the textfield is created after the calling of
the constructor.
I can't seem to find any properties for the xaml (xml) code to do this.

Does anybody know?

Thanks.

My System SpecsSystem Spec
Old 03-23-2006   #2 (permalink)
Drew Marsh


 
 

Re: set focus on a textfield on application startup

Bart van der Heijden wrote:

> I want to set the focus on my textfield when the application starts,
> but i don't know how to do this.
>
> I tried:
> txtIdentifier.Focus(); in the constructor of the codebehind of the
> xaml
> window code, but it seems that the textfield is created after the
> calling of
> the constructor.
> I can't seem to find any properties for the xaml (xml) code to do
> this.
> Does anybody know?


You cannot access controls in the constructor because they have not been
initialized yet. You must wait until the Loaded event of the Window has fired.
So if you hook up to the Loaded event of the Window and do the Focus() call
in the handler, you should be all set.

HTH,
Drew

___________________________________
Drew Marsh
Chief Software Architect
Mimeo.com, Inc. - http://www.mimeo.com
Microsoft C# / WPF MVP
Weblog - http://blog.hackedbrain.com/


My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Focus on application startup .NET General
Focus 6 Startup: Delete? Computer Access Damaged Software
Give focus to an InternetExplorer.Application object VB Script
Vista Startup Application Vista General
once iTunes looses the input focus, the CDROM device disappears inthe iTunes application Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46