Aracılığıyla paylaş


Nasıl Yapılır: ListBox'ın Kayan Performansını Artırma

If a ListBox contains many items, the user interface response can be slow when a user scrolls the ListBox by using the mouse wheel or dragging the thumb of a scrollbar. You can improve the performance of the ListBox when the user scrolls by setting the VirtualizingStackPanel.VirtualizationMode attached property to Recycling.

Örnek

Description

The following example creates a ListBox and sets VirtualizingStackPanel.VirtualizationMode to Recycling to improve performance during scrolling.

Code

<StackPanel>

  <StackPanel.Resources>
    <src:LotsOfItems x:Key="data"/>
  </StackPanel.Resources>

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

</StackPanel>

The following example shows the data that the previous example uses.

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