简体   繁体   English

当应用程序首次启动时,我无法获得此文本框的焦点

[英]I cannot get this textbox to get focus when the application first starts

...in Silverlight. ...在Silverlight中。 No tags in the title, and all that. 标题中没有标签,仅此而已。 I'm using Silverlight 4 on Chrome, though I've tried it on IE too. 我也在Chrome上使用Silverlight 4,尽管我也在IE上尝试过。 I've tried: 我试过了:

System.Windows.Browser.HtmlPage.Plugin.Focus();
this.Focus();
Dispatcher.BeginInvoke(() => { textBox_username.Focus(); });

And various combinations thereof (as suggested by a similar thread), as well as a separate method that was attached to the form loaded event. 以及它们的各种组合(由相似的线程建议),以及附加到表单加载事件的单独方法。 The above gets me the closest, since clicking anywhere on the page gives my textbox focus, like the plugin isn't getting focus still. 上面的内容使我最接近,因为单击页面上的任何位置都使我的文本框成为焦点,就像插件仍无法得到焦点。 Could be because this is the first window viewed? 可能是因为这是第一个查看的窗口?

I dont think that was because the first window viewed. 我不认为这是因为查看了第一个窗口。 try to put this.Focus(); 尝试放置this.Focus(); after your Dispatcher you set it false; 在您的调度程序之后,将其设置为false;

Change your code similar to below 更改您的代码,如下所示

public partial class MainPage : UserControl

{ {

public MainPage()
{
    InitializeComponent();
    this.Loaded += MainPage_Loaded;
}

void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    System.Windows.Browser.HtmlPage.Plugin.Focus();
    txtBox.UpdateLayout();
    txtBox.Focus();
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM