Export (0) Print
Expand All

VirtualizingStackPanel Class

Arranges and virtualizes content on a single line that is oriented either horizontally or vertically.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

'Declaration
Public Class VirtualizingStackPanel
	Inherits VirtualizingPanel
	Implements IScrollInfo
'Usage
Dim instance As VirtualizingStackPanel

public class VirtualizingStackPanel extends VirtualizingPanel implements IScrollInfo
public class VirtualizingStackPanel extends VirtualizingPanel implements IScrollInfo
<VirtualizingStackPanel>
  Children
</VirtualizingStackPanel>

In this context, the word "virtualize" refers to a technique by which a subset of user interface (UI) elements are generated from a larger number of data items based on which items are visible on-screen. Generating a large number of user interface (UI) elements when only a few elements might be on the screen at a given time is intensive with regard to both memory and processor. Through functionality that VirtualizingPanel provides, VirtualizingStackPanel calculates the number of visible items and works with the ItemContainerGenerator from an ItemsControl (such as ListBox or ListView) to create user interface (UI) elements only for visible items.

Virtualization in a StackPanel only occurs when items are data-bound. In scenarios with items that are not data-bound, a VirtualizingStackPanel offers no performance advantage over a StackPanel.

VirtualizingStackPanel is the default items host for the ListBox element. By default, the IsVirtualizing property is set to true.

When IsVirtualizing is set to false, a VirtualizingStackPanel behaves the same as a normal StackPanel.

The following example shows how to bind to an XML data source and virtualize the data source within a ListBox element by using Extensible Application Markup Language (XAML). Notice that the IsVirtualizing attached property is explicitly set to true.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      WindowTitle="VirtualizingStackPanel Sample" 
      Height="150"
      VerticalAlignment="Top">
    <Page.Resources>
        <XmlDataProvider x:Key="Leagues" Source="Leagues.xml" XPath="Leagues/League"/>
        
    <DataTemplate x:Key="NameDataStyle">
      <TextBlock Text="{Binding XPath=@name}" FontFamily="Arial" FontSize="12" Foreground="Black"/>
    </DataTemplate>
        
    </Page.Resources>
  <Border HorizontalAlignment="Left" 
          VerticalAlignment="Top" 
          BorderBrush="Black" 
          BorderThickness="2">
       <ScrollViewer>
      <StackPanel DataContext="{Binding Source={StaticResource Leagues}}">
          <TextBlock Text="{Binding XPath=@name}" FontFamily="Arial" FontSize="18" Foreground="Black"/>
              <ListBox VirtualizingStackPanel.IsVirtualizing="True" 
                       ItemsSource="{Binding XPath=Team}" 
                       ItemTemplate="{DynamicResource NameDataStyle}"/>      
      </StackPanel>
      </ScrollViewer>
  </Border>    
</Page>

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Media.Visual
         System.Windows.UIElement
           System.Windows.FrameworkElement
             System.Windows.Controls.Panel
               System.Windows.Controls.VirtualizingPanel
                System.Windows.Controls.VirtualizingStackPanel

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft