我有ItemsControl和VirtualizingStackPanel作为这样的项目面板:
<ItemsControl Style="{StaticResource ItemsControl}" Name="itemsControl"
Margin="0,100,0,0" HorizontalAlignment="Stretch" Height="80">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox />
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
风格如下:
<Style x:Key="ItemsControl" TargetType="ItemsControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ItemsControl">
<ScrollViewer VerticalScrollBarVisibility="Hidden"
HorizontalScrollBarVisibility="Visible">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我将一个包含 100.000 个元素的集合设置为ItemsSource并获得了非常好的性能。一切都很好,除了一件事。当我在其中一个文本框中输入文本然后开始滚动时,我看到该文本出现在整个列表中的任何地方!
我了解VirtualizingStackPanel的作用。它不断加载在我们滚动时变得可见的元素。我了解它的虚拟化技术的某些方面,但我不知道如何理解这种奇怪的行为。我找不到关于 WPF/Silverlight 虚拟化的好文档,所以,请解释一下发生了什么