在数据绑定代码中的DataGrid中列标题 [英] Databinding the DataGrid column header in code

查看:211
本文介绍了在数据绑定代码中的DataGrid中列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何数据绑定一个 WPF工具包的DataGrid 列标头值的在代码的(不XAML)?

 的DataGridColumn fooColumn =新DataGridTextColumn 
{
标题=富,
结合=新的Binding {路径=新的PropertyPath(BindingPath),
模式= BindingMode.OneWay}
};

这databinds列的单元的内容。但我怎么数据绑定的标题文字(富)本身(,比如说,在一个视图模型的字符串属性)?


解决方案

 的DataGridColumn fooColumn =新DataGridTextColumn 
{
结合=新的Binding {路径=新的PropertyPath(BindingPath),
模式= BindingMode.OneWay}
};

BindingOperations.SetBinding(fooColumn,DataGridColumn.HeaderProperty,新的绑定(富){源= 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆