Following xaml code snippet shows an example of implementing
<ListBox Name="ListBoxVirtualization" Height="110″ Margin="5″ VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" />
By default VirtualizingStackPanel is implemented on listBox. You can manually enable or disable virtualization on listbox control by setting VirtualizingStackPanel.IsVirtualizing property to "True" or "False". Internally VirtualizingStackPanel creates item container for each visible item. When item is not visible it destroys that item container. So some times with huge data it is very expensive task to create and destroy item container for each visible item.
In dotnet framework 4.0 and above Microsoft introduced VirtualizationMode. If you set VirtualizingStackPanel.VirtualizationMode = "Recycling" then each container will get reuse instead of destroy. You will get better performance by specifying VirtualizationMode to Recycling than basic default virtualization. If you don't specify VirtualizationMode then it will use default basic virtualization.
Let's assume in our case study we have listbox control with 1 million items and we can see only 10 items at a time. So the only 10 items which are currently visible will get created and maintained by the listbox. Instead of loading 1 million items at a time on listbox control it loads only 10 items which are visible.
I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.
Stay tuned to my blog, twitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.
C#,.NET,Architect,Intermediate,VS2010,.Net,Articles,Computer Tutorials,Virtualization , WPF