我试图将 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.
然后您需要将 CheckBox
的 IsChecked
属性绑定(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/