首页 文章

在代码中数据绑定DataGrid列 Headers

提问于
浏览
0

如何在代码(而不是XAML)中对WPF Toolkit DataGrid列 Headers 值进行数据绑定?

DataGridColumn fooColumn =  new DataGridTextColumn 
{
  Header = "Foo",
  Binding = new Binding {Path = new PropertyPath("BindingPath"), 
                         Mode = BindingMode.OneWay}
};

这对柱的细胞含量进行了数据分配 . 但是我如何对头文本(“Foo”)本身进行数据绑定(比如说,视图模型上的字符串属性)?

2 回答

  • 1
    DataGridColumn fooColumn =  new DataGridTextColumn 
    {
      Binding = new Binding {Path = new PropertyPath("BindingPath"), 
                             Mode = BindingMode.OneWay}
    };
    
    BindingOperations.SetBinding(fooColumn, DataGridColumn.HeaderProperty, new Binding("Foo") { Source = yourViewModel} );
    
  • 1

    在最新版本中看起来像Header is a Dependancy Property

相关问题