我有774个项目的List
。当我将其设置为绑定到Items
的ViewModel的List
属性(也是ItemsSource
)时,大约需要10秒钟以上的时间。
我已经尝试过Virtualizing an ItemsControl?的答案,但仍然无法正常工作-仍然需要10秒钟以上的时间。
这是未经修改的代码。请注意, ItemsControl
在ScrollViewer
内部。
XAML:
<Grid d:DataContext="{x:Static local:RulesListDesignmodel.Instance}" Background="{StaticResource ForegroundLightBrush}">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:RulesListItemControl />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
C#
ViewModelApplication.CurrentRulesListViewModel.Items = mList;
这是根据Virtualizing an ItemsControl? 的答案修改代码后的XAML(似乎要花10秒钟以上的时间):
<Grid d:DataContext="{x:Static local:RulesListDesignmodel.Instance}" Background="{StaticResource ForegroundLightBrush}">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding Items}"
VirtualizingStackPanel.IsVirtualizing="True"
ScrollViewer.CanContentScroll="True">
<ItemsControl.ItemTemplate>
<DataTemplate>
<local:RulesListItemControl />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<itemspaneltemplate>
<VirtualizingStackPanel />
</itemspaneltemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.Template>
<ControlTemplate>
<Border
BorderThickness="{TemplateBinding Border.BorderThickness}"
Padding="{TemplateBinding Control.Padding}"
BorderBrush="{TemplateBinding Border.BorderBrush}"
Background="{TemplateBinding Panel.Background}"
snapsToDevicePixels="True">
<ScrollViewer
Padding="{TemplateBinding Control.Padding}"
Focusable="False">
<ItemsPresenter
snapsToDevicePixels="{TemplateBinding UIElement.snapsToDevicePixels}" />
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>
</ScrollViewer>
</Grid>