Hello,
I have a RadGridView with child RadGridView . Both grids have a GridViewColumn whose visibility I would like to bind to a Property in my Model. This is working for the parent grid, but the child grid isn't in the right DataContext to access the property in my model.
The tables, stripped down for brevity:
<telerik:RadGridView AutoGenerateColumns="False" ItemsSource="{Binding ProductTypes.View}">
<telerik:RadGridView.ChildTableDefinitions>
<telerik:GridViewTableDefinition>
<telerik:GridViewTableDefinition.Relation>
<telerik:PropertyRelation ParentPropertyName="kcc_IncentiveProductTypeChildren" />
</telerik:GridViewTableDefinition.Relation>
</telerik:GridViewTableDefinition>
</telerik:RadGridView.ChildTableDefinitions>
<telerik:RadGridView.Columns>
<telerik:GridViewColumn IsVisible="{Binding DataContext.CanView, ElementName=LayoutRoot}" >
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Delete"/>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
</telerik:RadGridView.Columns>
<telerik:RadGridView.HierarchyChildTemplate>
<DataTemplate>
<telerik:RadGridView ItemsSource="{Binding kcc_IncentiveProductTypeChildren}" AutoGenerateColumns="False" >
<telerik:RadGridView.Columns>
<telerik:GridViewColumn IsVisible="{Binding DataContext.CanView, ElementName=LayoutRoot}" >
<telerik:GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="Delete"/>
</DataTemplate>
</telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</DataTemplate>
</telerik:RadGridView.HierarchyChildTemplate>
</telerik:RadGridView>
I need a way to bind to the IsVisible property of the GridViewColumn in the child Grid.
I considered applying a style from my static resources to the GridViewColumn to set the IsVisible property, but GridViewColumn does not have a Style property! I am not sure, but I don't think the other styles (header/footer/cell) will work on this property of the GridViewColumn.
<Style TargetType="telerik:GridViewColumn" x:Key="ViewPermissionColumn">
<Setter Property="IsVisible" Value="{Binding DataContext.CanView, ElementName=LayoutRoot}" />
</Style>
As a last option, I assume I'll need to handle an event on the main grid in order to set this value manually in the code behind. What event would I need?