0

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

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

此数据绑定列的单元格的内容。但是我如何数据绑定标题文本(“Foo”)本身(例如,视图模型上的字符串属性)?

4

1 回答 1

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} );
于 2009-08-21T15:44:17.523 回答