I'm trying to hide my GridView when it is empty with a trigger, but I'm having trouble with that. The problem seems to be that Items.Count doesn't update when the ItemsSource of the GridView is updated.
I have a GridView and a TextBlock like this:
And they reference these styles:
So the default is that the GridView is visible and the TextBlock is collapsed. When Items.Count is 0, i.e. when there are no records to show, the triggers make sure that the GridView is collapsed and the TextBlock is visible.
What happens is that the GridView never shows up but the TextBlock does, even though the GridView has records. If I use exactly the same code but swap out the GridView to a standard WPF ListBox it all works fine.
After some experimenting I've come to the conclusion that it is the Items.Count property that is the problem. It never gets updated. Initially the source of the GridView is empty and thus Items.Count is 0. But when I add items to the source (which I do immediately when the app starts) the Items.Count still remains 0.
Is this a known issue? How can I get around it? Or am I missing something?
Thanks // David
I have a GridView and a TextBlock like this:
<telerikGridView:RadGridView Name="MyGrid" |
ItemsSource="{Binding MyBindingList, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" |
Style="{StaticResource MyGridStyle}"> |
... |
</telerikGridView:RadGridView> |
<TextBlock Text="No records..." Style="{StaticResource NoRecordsTextStyle}" /> |
And they reference these styles:
<Style x:Key="MyGridStyle" TargetType="telerikGridView:RadGridView"> |
<Setter Property="Visibility" Value="Visible" /> |
<Style.Triggers> |
<DataTrigger Binding="{Binding ElementName=MyGrid, Path=Items.Count}" Value="0"> |
<Setter Property="Visibility" Value="Collapsed" /> |
</DataTrigger> |
</Style.Triggers> |
</Style> |
<Style x:Key="NoRecordsTextStyle" TargetType="TextBlock"> |
<Setter Property="Visibility" Value="Collapsed" /> |
<Style.Triggers> |
<DataTrigger Binding="{Binding ElementName=MyGrid, Path=Items.Count}" Value="0"> |
<Setter Property="Visibility" Value="Visible" /> |
</DataTrigger> |
</Style.Triggers> |
</Style> |
So the default is that the GridView is visible and the TextBlock is collapsed. When Items.Count is 0, i.e. when there are no records to show, the triggers make sure that the GridView is collapsed and the TextBlock is visible.
What happens is that the GridView never shows up but the TextBlock does, even though the GridView has records. If I use exactly the same code but swap out the GridView to a standard WPF ListBox it all works fine.
After some experimenting I've come to the conclusion that it is the Items.Count property that is the problem. It never gets updated. Initially the source of the GridView is empty and thus Items.Count is 0. But when I add items to the source (which I do immediately when the app starts) the Items.Count still remains 0.
Is this a known issue? How can I get around it? Or am I missing something?
Thanks // David