我的WPF应用程序将VirtualizingStackPanel用于ListView。滚动此列表可以在两台不同的机器上正常工作:我的主机(Windows 10 v1803构建17134.228)和一个虚拟机(Windows 10 v1607构建14393.2312)。如果我在其他VM(Windows 10 v1803内部版本17134.165)上运行相同的应用程序,并获得完全相同的副本,则列表滚动不会很顺畅-非常慢。简短地滚动几行就可以了(CacheLength),但是滚动更多行是非常糟糕的,就像虚拟化无法正常工作一样。
谁知道虚拟化是否依赖于Windows 10系统的任何组件或设置?
只需使用ListView粘贴一部分代码。
感谢帮助。
更新:抱歉,消息不灵通-滚动并不慢,滚动单元不是项而是整个页面(可能比页面还多)。因此滚动的视觉效果不好。
<ListView Grid.Row="1" Margin="0,-23,0,0" x:Name="LogMessagesListView" ItemsSource="{Binding DataModel.LogMessagesList}"
VirtualizingPanel.ScrollUnit="Item"
VirtualizingPanel.CacheLengthUnit="Page"
VirtualizingPanel.CacheLength="1.1"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
SelectionMode="Extended" SelectionChanged="LogMessagesListView_SelectionChanged" >
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<EventSetter Event="MouseDoubleClick" Handler="HandleLogMessageDoubleClick"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="{Binding DataContext.Runtime.ColumnWidthHighlight, ElementName=root }"/>
<ColumnDefinition Width="{Binding DataContext.Runtime.ColumnWidthLevel , ElementName=root}"/>
<ColumnDefinition Width="{Binding DataContext.Runtime.ColumnWidthDate, ElementName=root}"/>
<ColumnDefinition Width="{Binding DataContext.Runtime.ColumnWidthTime, ElementName=root}"/>
<ColumnDefinition Width="{Binding DataContext.Runtime.ColumnWidthProcess, ElementName=root }"/>
<ColumnDefinition Width="{Binding DataContext.Runtime.ColumnWidthNumber, ElementName=root }"/>
<ColumnDefinition Width="{Binding DataContext.Runtime.ColumnWidthCategory, ElementName=root }"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" Height="14" Width="15" Margin="-14,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="Green" CornerRadius="0" BorderThickness="0" Height="14" HorizontalAlignment="Stretch"
Visibility="{Binding IsBookmarked, Converter={StaticResource BoolToVisibility}}"/>
<Border Grid.Column="1" Background="Yellow" CornerRadius="0" BorderThickness="0" Height="14" HorizontalAlignment="Stretch"
Visibility="{Binding IsHighlighted, Converter={StaticResource BoolToVisibility}}"/>
<Border Grid.Column="2" Background="RoyalBlue" CornerRadius="0" BorderThickness="0" Height="14" HorizontalAlignment="Stretch"
Visibility="{Binding IsSearchTextHighlighted, Converter={StaticResource BoolToVisibility}}"/>
</Grid>
<Image Grid.Column="1" Source="{Binding Level, Converter={StaticResource LevelToImage}}" Width="14" Margin="-2,0,0,0"/>
<TextBlock Grid.Column="2" Text="{Binding LogDate}" Margin="1,0,0,1"/>
<TextBlock Grid.Column="3" Text="{Binding LogTime}" Margin="1,0,0,1"/>
<TextBlock Grid.Column="4" Text="{Binding ProcessName}" Margin="1,0,0,1"/>
<TextBlock Grid.Column="5" Text="{Binding MessageNumber}" Margin="1,0,0,1"/>
<TextBlock Grid.Column="6" Text="{Binding CategoryName}" Margin="1,0,0,1"/>
<local:TextBlockHighlight Grid.Column="7" Margin="1,0,0,1"
IsSelected="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}"
Highlighter="{Binding DataContext.DataModel.Highlighter, ElementName=root}"
LogMessage="{Binding .}"
DummyTrigger="{Binding MessageInlines}" />
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>