【问题标题】:How do I bind the visibility property of a DataGridTextColumn using code in WPF?如何使用 WPF 中的代码绑定 DataGridTextColumn 的可见性属性?
【发布时间】:2020-10-14 03:56:49
【问题描述】:

我正在尝试使用代码在 WPF 中绑定 DataGridTextColumn 的可见性属性。具体来说,我需要将它绑定到框架元素的数据上下文。

 <FrameworkElement x:Name="DataContextControl"/>

在 Xaml 中,我会这样做:

<DataGridTextColumn Visibility="{Binding DataContext, Source = {x:Reference DataContextControl}}">

我正在动态构建列,所以这里不是一个选项。由于 DataGridTextColumn 没有 setbinding 命令,如何以编程方式进行相同的绑定?

我尝试使用 SetValue 无济于事。

【问题讨论】:

标签: c# wpf xaml data-binding


【解决方案1】:

通过BindingOperations

var column = new DataGridTextColumn();
BindingOperations.SetBinding(
    column,
    DataGridColumn.VisibilityProperty,
    new Binding(...));

【讨论】:

    猜你喜欢
    • 2011-12-21
    • 2012-02-09
    • 2010-11-02
    • 1970-01-01
    • 2010-12-01
    • 2012-05-23
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多