I have a column in my RadGridView that displays some text and then also contains a button that should only be visible to users with permission to change the data. I'm using MVVM and the viewmodel exposes a boolean property named UserHasWriteAccess that indicates the user's permission level. The column and its datatemplate are defined as follows.
When UserHasWriteAccess is false, the button's visibility binding works fine most of the time (~99%) and the button does not show. However, as the user scrolls up and down through the grid, eventually intermittent binding errors will suddenly appear for a row or two for which the binding worked previously. Sometimes the user has to scroll up and down several times before it happens. Other times it's immediate. The errors say:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Telerik.Windows.Controls.RadGridView', AncestorLevel='1''. BindingExpression:Path=DataContext.UserHasWriteAccess; DataItem=null; target element is 'Button' (Name=''); target property is 'Visibility' (type 'Visibility')
Curiously, when I inspect an errored binding using Snoop, it suddenly works again.
Is there a known issue with ancestor binding in RadGridView?
<telerik:GridViewDataColumn Header="Reason Code"> <telerik:GridViewDataColumn.CellTemplate> <DataTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*" /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <TextBlock Text="Lorem ipsum" /> <Button Content="Edit" Height="23" HorizontalAlignment="Right" Margin="4,0,0,0" Visibility="{Binding DataContext.UserHasWriteAccess, Mode=OneTime, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}"> </Grid> </DataTemplate> </telerik:GridViewDataColumn.CellTemplate></telerik:GridViewDataColumn>When UserHasWriteAccess is false, the button's visibility binding works fine most of the time (~99%) and the button does not show. However, as the user scrolls up and down through the grid, eventually intermittent binding errors will suddenly appear for a row or two for which the binding worked previously. Sometimes the user has to scroll up and down several times before it happens. Other times it's immediate. The errors say:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Telerik.Windows.Controls.RadGridView', AncestorLevel='1''. BindingExpression:Path=DataContext.UserHasWriteAccess; DataItem=null; target element is 'Button' (Name=''); target property is 'Visibility' (type 'Visibility')
Curiously, when I inspect an errored binding using Snoop, it suddenly works again.
Is there a known issue with ancestor binding in RadGridView?