如何在代码(而不是XAML)中对WPF Toolkit DataGrid列标题值进行数据绑定?
DataGridColumn fooColumn = new DataGridTextColumn
{
Header = "Foo",
Binding = new Binding {Path = new PropertyPath("BindingPath"),
Mode = BindingMode.OneWay}
};
这会对色谱柱细胞的含量进行数据分析。但是如何对头文本(“Foo”)本身进行数据绑定(例如,视图模型上的字符串属性)?
答案 0 :(得分: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 :(得分:1)
在最新版本中看起来像标题is a Dependancy Property