Geeks With Blogs
ken spencer

I was wresting with this for a bit and trying to find a good solution.

Basically what happens is the browser loads the Html containing your Siverlight control but your control does not initially get the focus. So if you have say added 508C compliance (accessibility) to your control its not going to hit your 1st control on the SL page even though that page is showing. That’s because your SL code does not have the focus yet.

I searched and found several solutions. But almost all of them used JavaScript to do this. Then I found buried at the bottom of this link http://betaforums.silverlight.net/forums/p/112526/265506.aspx a nice little trick.

There are two minor steps to get this to work.

1st, add a using statement (C#) or Imports statement (VB) to: System.Windows.Browser.

2nd, add the following method call in the usercontrol_loaded event handler:

HtmlPage.Plugin.Focus();

or

HtmlPage.Plugin.Focus()

 

In my case, I wanted to set focus to Button1 when the page loads. So this is my entire code:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            HtmlPage.Plugin.Focus();

            Button1.Focus();          
        }

 

Enjoy.

Ken

Posted on Thursday, January 20, 2011 9:33 AM | Back to top


Comments on this post: Siverlight: Setting focus to the SL page when the browser loads it

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © xamlnotes | Powered by: GeeksWithBlogs.net