关注 WPF 中的 FrameworkElementFactory

问题描述

我在 WPF 程序中使用 FrameworkElementFactory 作为以下代码

FrameworkElementFactory txt1 = new FrameworkElementFactory(typeof(TextBox));

我尝试以编程方式关注此 FrameworkElementFactory,并尝试使用 VisualTreeHelper.HitTest。有什么方法可以像 txt1.Focus 或 HitTest 一样关注 *txt1 * 吗?

我在 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
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)