How to set focus on TextBox in Silverlight 4 out-of-browser popup

后端 未结 6 1052
后悔当初
后悔当初 2020-12-18 10:30

I have a simple ChildWindow popup in Silverlight 4 (beta).

Important: This is an out-of-browser application.

i want to auto

6条回答
  •  眼角桃花
    2020-12-18 10:37

    You are on the right track. You need to handle for two test cases:
    1. Setting the focus in the browser. 2. Setting the focus out of the browser.

    Your code you that you showed in the Loaded event will work perfectly fine out of the browser. All that is necessary is to refactor it to handle both cases:

    private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
    {
        if (App.current.IsRunningOutOfBrowser)
        {
            textBox1.Focus();
        }
        else
        {
            System.Windows.Browser.HtmlPage.Plugin.Focus();
            textBox1.Focus();
        }
    }
    

    That should do the trick for you.

提交回复
热议问题