我的ListView性能非常慢,特别是在排序和过滤方面。有人建议使用虚拟化,但我在ListView中使用WrapPanel。如何提升性能。
<ListView ManipulationBoundaryFeedback="liveGrid_ManipulationBoundaryFeedback" ScrollViewer.HorizontalScrollBarVisibility="Auto" ItemsSource="{Binding Source={StaticResource cvs}}" Style="{DynamicResource LiveGridListView}" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent" x:Name="liveGrid" SelectionChanged="PlayerNodeSelected">
<ListView.Resources>
<sys:Double x:Key="{x:Static SystemParameters.HorizontalScrollBarHeightKey}">9</sys:Double>
<SolidColorBrush x:Key="ScrollBar.MouseOver.Thumb" Color="#fff"/>
<SolidColorBrush x:Key="ScrollBar.Pressed.Thumb" Color="#fff"/>
<SolidColorBrush x:Key="ScrollBar.Static.Thumb" Color="#fff"/>
</ListView.Resources>
<ListView.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Padding" Value="0"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Grid Margin="0,10,20,0">
<controls:PlayerIsConnected Visibility="{Binding IsConnected, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<controls:PlayerNeverConnected Visibility="{Binding IsPlayerNeveConnectedShown, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<controls:PlayerHadConnected Visibility="{Binding HasConnectedIsNotConnected, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,60,0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<StackPanel Orientation="Vertical">
<Grid Height="28">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<TextBlock VerticalAlignment="Bottom" Margin="0,0,0,0" Foreground="White" FontFamily="{StaticResource BEGroteskMedium}" FontSize="14" Text="{Binding Name}"/>
</StackPanel>
<Border Grid.Column="1" Height="1" Margin="06,20,20,0" BorderBrush="White" BorderThickness="0,0,0,1"/>
</Grid>
<ItemsControl>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Height="593" Orientation="Vertical"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsPresenter/>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
添加了我的XAML代码。它还具有分组功能。 listviewitem是图像和文本的组合。我在一列中显示4行,并且根据宽度,屏幕上最多可显示20个项目