c# - Xceed 数据网格列可见性绑定(bind)

标签 c# wpf datagrid xceed-datagrid

我试图将 Xceed 数据网格中列的可见性绑定(bind)到复选框的 IsChecked 值。

<xcdg:DataGridControl ReadOnly="{Binding ElementName=ShowReferenceColumn, Path=IsChecked}">
    <xcdg:DataGridControl.Columns>
        <xcdg:Column FieldName="Reference" Visible="{Binding ElementName=ShowReferenceColumn, Path=IsChecked}" />
    </xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>

datagrid 的 ReadOnly 属性通过更改复选框 IsChecked 值得到更新,但列的可见性没有改变。我是否在列的绑定(bind)中遗漏了某些内容?

编辑:

此处的 ReadOnly 属性是我能够使绑定(bind)生效的属性示例。实际上,它不会绑定(bind)到用于列可见性的同一个复选框。

最佳答案

试试这个:

<xcdg:Column FieldName="Reference" 
             Visible="{Binding RelativeSource={RelativeSource Self}, Path=DataGridControl.ReadOnly}" />

编辑:

The ReadOnly property here is an example of a property where I was able to get the binding to work. In reality it is not going to be binding to the same checkbox as used for the column visibility.

然后您需要将 CheckBoxIsChecked 属性绑定(bind)到 View 模型的源属性,然后绑定(bind) Visible 属性同一源属性的列:

<xcdg:Column FieldName="Reference" 
             Visible="{Binding RelativeSource={RelativeSource Self}, Path=DataGridControl.DataContext.BooleanSourceProperty}" />

您不能在此上下文中使用 ElementName,因为列和 CheckBox 不属于同一名称范围。

关于c# - Xceed 数据网格列可见性绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48625169/

相关文章:

c# - 将大型 CLOB 对象转换为 .NET 字符串以放入 DataGridView 单元格

c# - 如果绑定(bind)不匹配,则将项目添加到 itemssource

C# ChromiumWeb 浏览器 : Prevent control from stealing focus

c# - 将行为附加到 MetroWindow 失败并导致错误的样式

c# - 当值为0000-00-00 00 :00:00时如何处理mysql datetime列

具有许多用户控件的 WPF 应用程序

c# - 最适合模型的位图类

c# - 将 WPF DataGrid 绑定(bind)到 List<Interface>

c# - 覆盖 Entity Framework 连接逻辑

c# - 编译器错误消息 : CS0118: 'System.Configuration.ConfigurationManager.AppSettings' is a 'property' but is used like a 'method'