C# 带括号和绑定的PropertyPath

C# 带括号和绑定的PropertyPath,c#,wpf,binding,C#,Wpf,Binding,我正在代码背后创建绑定 IEnumerable<IDictionary<string, object>> rows = dg1.ItemsSource.OfType<IDictionary<string, object>>(); IEnumerable<string> columns = rows.SelectMany(d => d.Keys). Distinct(StringComparer.OrdinalIgn

我正在代码背后创建绑定

IEnumerable<IDictionary<string, object>> rows = dg1.ItemsSource.OfType<IDictionary<string, object>>();
        IEnumerable<string> columns = rows.SelectMany(d => d.Keys). Distinct(StringComparer.OrdinalIgnoreCase);
        foreach (string column in columns)
        {
            DataGridTemplateColumn col = new DataGridTemplateColumn();
             col.Header = column;

             // Create a factory. This will create the controls in each cell of this
             // column as needed.
             FrameworkElementFactory factory =
                 new FrameworkElementFactory(typeof(TextBox));

              **Binding b = new Binding() { Path=new PropertyPath(column)};**


             b.Mode = BindingMode.TwoWay;
             b.UpdateSourceTrigger = UpdateSourceTrigger.LostFocus;
            // b.StringFormat = "d";
             b.Converter = new MyConverter();
             b.ConverterParameter = dg1;
             factory.SetValue(TextBox.TextProperty, b);
            // factory.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
             // Create the template itself, and add the factory to it.
             DataTemplate cellEditingTemplate = new DataTemplate();
             cellEditingTemplate.VisualTree = factory;

             col.CellTemplate = cellEditingTemplate;

             dg1.Columns.Add(col);
此外,如果PropertyPath的值类似于abc,那么绑定也会失败

避免此类约束性问题的解决方案是什么

编辑:


我完全不明白你的意思。。你要那个装订做什么?什么样的属性是一个??它是一个动态用户界面,用户可以在其中添加列,他们可以添加任何字符串,如abc或abc或其他任何东西,但绑定会与这些东西断开。但列不是一个属性,它只是一个字符串,如何使用字符串对象的值解析属性当开发人员将“动态”和“用户界面”这两个词组合在一起时,我立即意识到他们误解或忽视了正确的方法,即MVVM、数据模板和WPF中的类似内容。由于这些方面的原因,WPF UI本质上是动态的,我不明白创建到无效属性的绑定有什么意义。
public Window3()
{
        try
        {
            InitializeComponent();

            Binding b = new Binding() { Path = new PropertyPath("a(") };
        }
        catch (Exception)
        {

            throw;
        }
}