troubleshooting Question

How to focus in Silverlight control at start page (html or aspx) when using Google Chrome?

Avatar of Joni Kettunen
Joni KettunenFlag for Finland asked on
Microsoft DevelopmentWeb BrowsersC#
1 Comment1 Solution1628 ViewsLast Modified:
I need to get Google Chrome to focus my silverlight component. With firefox and IE my focus can be easily gained using the code shown at the end of question. The code is located at the MainPage which is the first page loaded at the startup.

I need to get focus in login dialog after first page is loaded. Then user writes his username and password etc. Without automatic focus user has to click login dialog, which is a nuisance.

With other browsers I can get focus to the plugin using method call:
System.Windows.Browser.HtmlPage.Plugin.Focus()

In SL 2 javascript was used to gain focus. But that doesn't work with SL 4 to my knowledge.

I am using Silverlight 4 and C#.

Could you help me, please?
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
    // Use dispatcher to avoid silly SL 3 problem. Using SL 3
    // code had to call UpdateLayout method before focus.
    this.Dispatcher.BeginInvoke(() => myTextBox.Focus());
    // Get focus to SL component at web page
    System.Windows.Browser.HtmlPage.Plugin.Focus();
}
ASKER CERTIFIED SOLUTION
Joni Kettunen
Senior Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros