Link to home
Start Free TrialLog in
Avatar of Joni Kettunen
Joni KettunenFlag for Finland

asked on

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

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()

Open in new window


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();
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Joni Kettunen
Joni Kettunen
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial