在代码中数据绑定DataGrid列标题 [英] Databinding the DataGrid column header in code
本文介绍了在代码中数据绑定DataGrid列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何数据绑定 WPF Toolkit DataGrid 列标题值在代码(不是XAML)?
DataGridColumn fooColumn = new DataGridTextColumn
{
标题=Foo,
Binding = new Binding {Path = new PropertyPath(BindingPath),
Mode = BindingMode.OneWay}
};
此数据绑定列的单元格内容。但是我如何将头文本(Foo)本身(例如,在viewmodel上的字符串属性)数据绑定?
解决方案
pre> DataGridColumn fooColumn = new DataGridTextColumn
{
Binding = new Binding {Path = new PropertyPath(BindingPath),
Mode = BindingMode.OneWay}
};
BindingOperations.SetBinding(fooColumn,DataGridColumn.HeaderProperty,new Binding(Foo){Source = yourViewModel});
How do I databind a WPF Toolkit DataGrid column header value in code (not XAML)?
DataGridColumn fooColumn = new DataGridTextColumn
{
Header = "Foo",
Binding = new Binding {Path = new PropertyPath("BindingPath"),
Mode = BindingMode.OneWay}
};
This databinds the content of the cells of the column. But how do I databind the header text ("Foo") itself (to, say, a string property on a viewmodel)?
解决方案
DataGridColumn fooColumn = new DataGridTextColumn
{
Binding = new Binding {Path = new PropertyPath("BindingPath"),
Mode = BindingMode.OneWay}
};
BindingOperations.SetBinding(fooColumn, DataGridColumn.HeaderProperty, new Binding("Foo") { Source = yourViewModel} );
这篇关于在代码中数据绑定DataGrid列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文