This blog will cover virtualization technologies in WPF.
1. Data virtualization Typically, we say that virtualization means that the data source is not fully loaded, loading only the data that is currently needed for display to the user. This scenario reminds us of the data paging display, which requests the data based on the number of pages when the data for a particular page is needed.
WPF did not provide support for the data virtualization primitive ecosystem, which we could have implemented using paging-related technologies. This is described in my previous blog WPF implementation Datagrid/listview pagination control.
2. UI virtualization is an optimization that renders data items for data containers. For example, there are 10,000 item in a Listview/listbox control, but only 10 visible, then only 10 item is rendered and displayed, and the remaining 9,990 item is not instantiated and displayed. This can improve the performance of the program.
The VirtualizingStackPanel container in WPF is the container that implements the UI virtualization, and VirtualizingStackPanel is also the default data container for Listbox/listview.
Here's an example of the impact of turning on UI virtualization and turning off UI virtualization on program performance.
<x:name= "Virtualizationlistview" Virtualizingpanel.virtualizationmode= "Recycling" virtualizingpanel.isvirtualizing = "True" />
PublicMainWindow () {InitializeComponent (); This. Loaded + =Delegate{List<string> items =Newlist<string>(); for(inti =0; I <10000; i++) {items. ADD (string. Concat ("Item", i)); } This. Virtualizationlistview.itemssource =items; };}
At this point, when scrolling through ScrollBar, the memory fluctuation is not obvious.
Virtualizingpanel.virtualizationmode= "Recycling" means that the new item is not looped, such as item1--item20 visible at this time, dragging the scrollbar to Item100, When returning from Item100 to ITEM1--ITEM20, the ITEM1--ITEM20 is not instantiated again. By default virtualizingpanel.virtualizationmode= "standard". When the ListView is scrolling, the memory is incremented.
When UI virtualization is turned off, memory changes are significant, as the program initializes all of the 10,000 data in the ListView.
When encountering the above scenario, it is reasonable to use virtualization technology to improve the performance of the program.
Thank you for reading.
[WPF] WPF Data Virtualization and UI Virtualization