Virtualizing StackPanel generates container items when needed & throws them from memory when they are no longer in the view. When the pa...
-
Published by Kunal Chowdhury
Virtualizing StackPanel generates container items when needed & throws them from memory when they are no longer in the view. When the panel has huge number of items, at that time there is no need to keep the extra items in memory which are not in view. This solves the memory problem.
If you are populating a huge number of items in any panel, then it is a better idea to use the Virtualization. But, due to throwing away of the extra items & recreating them when in view, costs some extra processing power when the Virtualizing StackPanel uses the default Standard Mode. To solve this issue, just change the virtualization mode to "Recycling". This is called as Container Recycling, which introduced in .Net 3.5 SP1 as a new feature.
By default, this recycling mode is turned off. To enable the container recycling, first turn on the Virtualizing StackPanel with “VirtualizationModeProperty” as “Recycling”.
<WrapPanel x:Name="wrpPanel" VirtualizingStackPanel.IsVirtualizing="true" VirtualizingStackPanel.VirtualizationMode="Recycling" />
You can also use GetVirtualizationMode() & SetVirtualizationMode() to get or set the current mode.
Solution Architect & Former Microsoft MVP
Kunal Chowdhury is an enterprise solution architect and former multi-year Microsoft MVP. He is the author of three technical books: Windows Presentation Foundation Development Cookbook, Mastering Visual Studio 2017, and the Mastering Visual Studio 2019.
He publishes technical articles on Kunal-Chowdhury.com.