[英]I cannot get this textbox to get focus when the application first starts
...在Silverlight中。 标题中没有标签,仅此而已。 我也在Chrome上使用Silverlight 4,尽管我也在IE上尝试过。 我试过了:
System.Windows.Browser.HtmlPage.Plugin.Focus();
this.Focus();
Dispatcher.BeginInvoke(() => { textBox_username.Focus(); });
以及它们的各种组合(由相似的线程建议),以及附加到表单加载事件的单独方法。 上面的内容使我最接近,因为单击页面上的任何位置都使我的文本框成为焦点,就像插件仍无法得到焦点。 可能是因为这是第一个查看的窗口?
我不认为这是因为查看了第一个窗口。 尝试放置this.Focus();
在您的调度程序之后,将其设置为false;
更改您的代码,如下所示
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.