我的ItemsControl與VirtualizingStackPanel作爲項目小組是這樣的:VirtualizingStackPanel不清除文本框的文本在ItemTemplate
<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>
我設置作爲ItemsSource 100.000元素的集合,並獲得非常好的表現。除了一件事以外,一切都很好。當我在其中一個文本框中輸入文本,然後開始滾動時,我看到該文本出現在整個列表中的任何地方!
我明白VirtualizingStackPanel是做什麼的。它不斷加載在滾動時可見的元素。我理解它的虛擬化技術的一些方面,但我不知道如何理解這種奇怪的行爲。我沒有找到關於WPF/Silverlight虛擬化的好文檔,所以,請解釋我發生了什麼
我對datagird中的單選按鈕有同樣的問題,並通過爲每個單元添加單獨的編輯模板來解決它。感謝@Rachel,現在很清楚如何解決這類問題 –