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

11,812

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

Share:
11,812

Related videos on Youtube

Julius
Author by

Julius

London based Software developer

Updated on September 15, 2022

Comments

  • Julius
    Julius over 1 year

    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.

  • Julius
    Julius over 10 years
    Interesting clarification concerning the direction of the EnableRowVirtualization/EnableColumnVirtualization properties. Can you further clarify the impact of setting the attached property instead of/as well as the EnableRowVirtualization/EnableColumnVirtualization properties? I understand that they turn on/off the same sort of behaviour, but I still don't understand whether one can be used over the other, i.e. do they have completely overlapping responsibilities, or actually do different things under the hood?
  • Gayot Fow
    Gayot Fow over 10 years
    The behaviour is implemented at the ItemsControl level, so affects classes derived from it. 'Under the hood' there are no conspicuous differences in the algorithm other than directionality. Also... It's not really a choice of using one setting over the other because native properties should be used when they are available.