<ItemsControl ItemsSource="{Binding MemberInfos}" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" VirtualizingPanel.CacheLength="50"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel></VirtualizingStackPanel> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.Template> <ControlTemplate TargetType="ItemsControl"> <ScrollViewer VerticalScrollBarVisibility="Auto" CanContentScroll="True"> <ItemsPresenter></ItemsPresenter> <ScrollViewer.Resources> <Style TargetType="ScrollBar"> <Setter Property="Width" Value="6"/> <Setter Property="MinWidth" Value="6"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ScrollBar"> <Grid> <Rectangle Width="{TemplateBinding Width}" Fill="White"/> <Track x:Name="PART_Track" IsDirectionReversed="True"> <Track.DecreaseRepeatButton> <RepeatButton Command="ScrollBar.LineUpCommand" Visibility="Collapsed"/> </Track.DecreaseRepeatButton> <Track.IncreaseRepeatButton> <RepeatButton Command="ScrollBar.LineDownCommand" Visibility="Collapsed"/> </Track.IncreaseRepeatButton> <Track.Thumb> <Thumb Background="#D3D7DD"/> </Track.Thumb> </Track> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> </ScrollViewer.Resources> </ScrollViewer> </ControlTemplate> </ItemsControl.Template> <ItemsControl.ItemTemplate> <DataTemplate> <local:MembersListItem/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl>
标签:虚拟化,ItemsControl,数据量,WPF,优化,卡顿 From: https://www.cnblogs.com/HansZimmer/p/17784118.html