VirtualizationMode 枚举


指定 VirtualizingStackPanel 用来管理子项虚拟化的方法。Specifies the method the VirtualizingStackPanel uses to manage virtualizing its child items.

public enum class VirtualizationMode
public enum VirtualizationMode
type VirtualizationMode = 
Public Enum VirtualizationMode


Recycling 1

重用项容器。Reuse the item containers.

Standard 0

创建并放弃项容器。Create and discard the item containers.


下面的示例创建一个ListBox , 并将VirtualizationMode附加属性设置为 "回收"。The following example creates a ListBox and sets the VirtualizationMode attached property to Recycling.


    <src:LotsOfItems x:Key="data"/>

  <ListBox Height="150" ItemsSource="{StaticResource data}" 
             VirtualizingStackPanel.VirtualizationMode="Recycling" />


下面的示例显示了上一示例中使用的数据。The following example shows the data used in the previous example.

public class LotsOfItems : ObservableCollection<String>
    public LotsOfItems()
        for (int i = 0; i < 1000; ++i)
            Add("item " + i.ToString());
Public Class LotsOfItems
    Inherits ObservableCollection(Of String)
    Public Sub New()
        For i As Integer = 0 To 999
            Add("item " & i.ToString())
    End Sub
End Class


默认情况下, VirtualizingStackPanel将为每个可见项创建一个项容器, 并在不再需要它时 (例如, 当项滚动到视图之外时) 将其丢弃。By default, a VirtualizingStackPanel creates an item container for each visible item and discards it when it is no longer needed (such as when the item is scrolled out of view). ItemsControl当包含多个项时, 创建和放弃项容器的过程可能会对性能产生负面影响。When an ItemsControl contains a many items, the process of creating and discarding item containers can negatively affect performance. VirtualizationMode设置为回收时, 将VirtualizingStackPanel重用项容器, 而不是每次都创建一个新的。When VirtualizationMode is set to Recycling, the VirtualizingStackPanel reuses item containers instead of creating a new one each time.

VirtualizingStackPanel无法回收项容器时, 它使用标准虚拟化模式, 即为每个项创建和丢弃项容器。When VirtualizingStackPanel cannot recycle item containers, it uses the standard mode of virtualization, which is to create and discard item containers for each item. 以下列表描述了无法回收项VirtualizingStackPanel容器时的情况:The following list describes cases when the VirtualizingStackPanel cannot recycle item containers: