Tech Tock

Time is of the essence.

Focus on Silverlight App At Startup – Problem Solved

I finally figured out the way to set focus to a Silverlight control on start-up:  just set focus to your app, then set the control focus on the dispatcher to give the app time to process whatever it needs to when it gets focus.  In other words, in the root visual constructor use this code:

HtmlPage.Plugin.Focus();
Dispatcher.BeginInvoke(() => YourControl.Focus());

This may be the first (and probably the last) actual Silverlight mystery I have solved.  A couple months ago, I was searching the internet for the way to do this and found absolutely nothing.

Yippee-Kai-Yay for me 😉

Advertisements

April 20, 2010 - Posted by | Uncategorized | , ,

3 Comments »

  1. […] Its funny because its true.  When there’s property setting or UI resizing or several other common UI related problems, putting the next statement on the Dispatcher to let an operation complete first is just the trick.  Handy as Duct Tape.  Case in point, the focus at startup issue. […]

    Pingback by Dispatcher.BeginInvoke: UI Duct Tape « Tech Tock | May 13, 2010 | Reply

  2. […] Its funny because its true.  When there’s property setting or UI resizing or several other common UI related problems, putting the next statement on the Dispatcher to let an operation complete first is just the trick.  Handy as Duct Tape.  Case in point, the focus at startup issue. […]

    Pingback by Dispatcher.BeginInvoke: UI Duct Tape « Tech Tock | May 13, 2010 | Reply

  3. In SL5 (haven’t tested previous version behavior), this doesn’t work for Chrome or Firefox, only IE… Any ideas to make this work on all browsers?

    Comment by faxedhead | August 27, 2012 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: