What is the difference between a stackpanel and a virtualizingstackpanel in 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.
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.
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.
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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With