Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a stackpanel and a virtualizingstackpanel in WPF?

Tags:

What is the difference between a stackpanel and a virtualizingstackpanel in WPF?

like image 475
Peter Avatar asked Mar 20 '09 13:03

Peter


People also ask

What is VirtualizingStackPanel WPF?

The VirtualizingStackPanel calculates the number of visible items and works with the ItemContainerGenerator from an ItemsControl (such as ListBox or ListView) to create UI elements only for visible items.

What is a StackPanel?

StackPanel is a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically. By default, StackPanel stacks items vertically from top to bottom in the order they are declared. You can set the Orientation property to Horizontal to stack items from left to right.

What is user interface virtualization in WPF?

Virtualization technique in WPF improves the rendering performance of UI elements. By applying virtualization, the layout system ensures that only the visible items of a container are rendered on the screen.

What is virtualization C#?

Virtualization is a technique that can be used to improve the performance of data-bound item controls that contain a very large list of items. Imagine a ListBox in a WPF application (or any of the other XAML technologies, for that matter) that's data bound to a source that contains a 100,000 items.


1 Answers

A VirtualizingStackPanel can offer performance benefits when working with very large collections. It does so by only rendering and processing a subset of the data which is visible to the user vs. processing the entire list of data. By creating only UI elements for the visible items, this can greatly reduce the amount of work it has to do.

This is really only handy though if

  1. You are data binding non-UI elements or elements for which UI must be created in the particular panel
  2. You are data binding a lot of data

A StackPanel on the other hand, will up front create the controls for all elements contained within the StackPanel.

The VirtualizingStackPanel MSDN page has a decent discussion: http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.aspx

like image 162
JaredPar Avatar answered Sep 26 '22 17:09

JaredPar