我在我的 WPF 程序中使用 FrameworkElementFactory 作为以下代码:
FrameworkElementFactory txt1 = new FrameworkElementFactory(typeof(TextBox));
我尝试以编程方式关注此 FrameworkElementFactory,并使用 VisualTreeHelper.HitTest 进行了尝试。有什么方法可以专注于 *txt1 * liketxt1.Focus
或 HitTest 吗?
我在 Listview 上创建了它并以编程方式填写了它的列。并根据以下代码设计这个Listview:
for (int x = 0; x <= obj.ClmnDegerler.Length - 1; x++)
{
var GridViewColumn1 = new GridViewColumn();
txt1 = new FrameworkElementFactory(typeof(TextBox));
txt1.SetValue(TextBox.HeightProperty, 20.0);
txt1.SetValue(TextBox.WidthProperty, clmnwidth);
dataTemplate = new DataTemplate();
dataTemplate.VisualTree = txt1;
GridViewColumn1.CellTemplate = dataTemplate;
this.UGridview1.Columns.Add(GridViewColumn1);
}
我通过 xaml 创建了一个按钮,当我想单击按钮时,我想专注于 txt1
private void Button_Click(object sender, RoutedEventArgs e)
{
//txt1.Focus(); not working
}