Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between WPF DataGrid's EnableRowVirtualization and VirtualizingStackPanel.IsVirtualizing properties

There is almost no information out there about the impact of setting;

VirtualizingStackPanel.IsVirtualizing="True" 

and

EnableRowVirtualization="True" EnableColumnVirtualization="True". 

Can someone clarify what the difference is?

Also, as an added bonus, can anyone clarify if EnableRowVirtualization and EnableColumnVirtualization actually do anything on the 3.5 grid as the MSDN documentation only lists these properties back to 4.0, but they definitely exist in 3.5?

Thanks.

like image 332
Julius Avatar asked Sep 24 '13 08:09

Julius


1 Answers

Both IsVirtualizing and EnableRowVirtualization/EnableColumnVirtualization operate on the same principle, which is that items are visualized only when needed and the containers are reused.

Essentially, the Panel (or Grid) keeps track of what is visible and if this is changed, it uses an internal class, 'ItemContainerGenerator', to size and build new items (https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.itemcontainergenerator).

The motivation for both is that the containers are only generated on demand thus saving memory and improving performance.

As to why there are two: the Panel is designed to extend in a single direction only, either horizontal or vertical; so they implemented a single attached property for it. A Grid, on the other hand, extends in two dimensions, so they implemented a property for each dimension.

The other difference is academic: IsVirtualizing is an attached property, wherease its counterparts for the Grid are native properties. No clue as to why they opted for this difference...

Relevant links are https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.datagrid.enablerowvirtualization and https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.virtualizingstackpanel.isvirtualizing

like image 135
Gayot Fow Avatar answered Oct 11 '22 16:10

Gayot Fow