private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
//动态添加TextBox到ScrollViewer的StackPanel中
txt = new TextBox[5];
for (int i = 0; i < 5; i++)
{
txt[i] = new TextBox();
txt[i].Width = 200;
txt[i].Height = 30;
txt[i].SetValue(Canvas.TopProperty, Convert.ToDouble(i * 30 + (i + 1) * 10));
txt[i].SetValue(Canvas.LeftProperty, Convert.ToDouble(10));
Main.Children.Add(txt[i]);
}
'===========让控件得到焦点的关键代码Start===========
HtmlPage.Plugin.Focus();
txt[0].Focus();
'===========让控件得到焦点的关键代码End===========
}
HtmlPage.Plugin.Focus(); 需要引用命名空间using System.Windows.Browser;