I am trying to bind the visibility of columns in an Xceed datagrid to the IsChecked value of a checkbox.
<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>
The ReadOnly property of the datagrid is getting updated by the chaning of the checkbox IsChecked value, but the visibility of the column is not changing. Am I missing something in the binding on the column?
Edit:
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.
Try this:
<xcdg:Column FieldName="Reference"
Visible="{Binding RelativeSource={RelativeSource Self}, Path=DataGridControl.ReadOnly}" />
Edit:
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.
Then you need to bind the IsChecked
property of the CheckBox
to a source property of the view model and then bind the Visible
property of the column to the same source property:
<xcdg:Column FieldName="Reference"
Visible="{Binding RelativeSource={RelativeSource Self}, Path=DataGridControl.DataContext.BooleanSourceProperty}" />
You cannot use ElementName
in this context as the column and the CheckBox
don't belong to the same namescope.