在代码中对 DataGrid 列标题进行数据绑定

发布于 2024-08-02 03:07:28 字数 440 浏览 1 评论 0原文

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

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

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

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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2024-08-09 03:07:28
DataGridColumn fooColumn =  new DataGridTextColumn 
{
  Binding = new Binding {Path = new PropertyPath("BindingPath"), 
                         Mode = BindingMode.OneWay}
};

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

BindingOperations.SetBinding(fooColumn, DataGridColumn.HeaderProperty, new Binding("Foo") { Source = yourViewModel} );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文