2 years ago
#73891
Athena_92
Groups went missing in ListView after expanding and collapsing expander in WPF C# with IsVirtualizing set to True
I have ListView and there is Grouping going on in it for one of the field 'Name'. The ItemSource is bound to an ObservableCollection. Somehow when grouping is applied, the virtualization is turn off and because I am displaying large amount of data, I turned virtualization back on.
But I notice something strange on the group expender, once I expand and collapse a group, the groups below it will be gone missing. To illustrate this, below are the screenshots I captured, screenshot
Here's my XAML for the ListView. When I set VirtualizingPanel.IsVirtualizing="True", the above problem is seen.
<ListView Name="ReportListView" Grid.Row="1"
ItemsSource="{Binding LalaCollection}"
AlternationCount="2"
ScrollViewer.VerticalScrollBarVisibility="Visible"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.IsVirtualizingWhenGrouping="True">
<ListView.View>
<GridView>
<GridViewColumn Header="Col A" DisplayMemberBinding="{Binding FailureType}" Width="Auto"/>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" Width="Auto"/>
<GridViewColumn Header="Col B" DisplayMemberBinding="{Binding NodeName}" Width="Auto"/>
<GridViewColumn Header="Col C" DisplayMemberBinding="{Binding DeviceName}" Width="Auto"/>
<GridViewColumn Header="Col D" DisplayMemberBinding="{Binding DateTime}" Width="Auto"/>
</GridView>
</ListView.View>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate>
<Expander IsExpanded="False">
<Expander.Header>
< StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" VerticalAlignment="Bottom" Background="{StaticResource BackgroundColor}" Foreground="{StaticResource ForegroundColor}"/>
<TextBlock Text="{Binding ItemCount}" Foreground="Silver" FontStyle="Italic" Margin="10,0,0,0" VerticalAlignment="Bottom" />
<TextBlock Text=" item(s)" Foreground="Silver" FontStyle="Italic" VerticalAlignment="Bottom" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
</ListView>
Not sure if this is a limitation for ListView Virtuaization when grouping is enabled, I am also thinking of other way to present this ObservableCollection to user with grouping in it.
c#
wpf
listview
observablecollection
virtualization
0 Answers
Your Answer