我的 WPF 应用程序将 VirtualizingStackPanel 用于 ListView。滚动此列表在两台不同的机器上运行良好:我的主机(Windows 10 v1803 build 17134.228)和一台虚拟机(Windows 10 v1607 build 14393.2312)。如果我在我的另一个虚拟机(Windows 10 v1803 build 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>