WPF DataGrid 的 EnableRowVirtualization 和 VirtualizingStackPanel.IsVirtualizing 属性之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18976856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:43:12  来源:igfitidea点击:

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

c#wpfdatagridui-virtualization

提问by Julius

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?

此外,作为一个额外的好处,任何人都可以澄清 EnableRowVirtualization 和 EnableColumnVirtualization 是否真的在 3.5 网格上执行任何操作,因为 MSDN 文档仅将这些属性列出回 4.0,但它们肯定存在于 3.5 中?

Thanks.

谢谢。

采纳答案by Gayot Fow

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

无论IsVirtualizingEnableRowVirtualization/EnableColumnVirtualization原理相同,这是仅在需要时项目可视化和容器被重新使用操作。

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).

本质上,Panel(或Grid)会跟踪可见的内容,如果更改,它会使用内部类'ItemContainerGenerator', 来调整和构建新项目的大小 ( 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 Panelis 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.

至于为什么有两个:Panel设计为仅在一个方向上延伸,水平或垂直;所以他们为它实现了一个附加的属性。Grid另一方面,A在两个维度上扩展,因此他们为每个维度实现了一个属性。

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

另一个区别是学术性的: IsVirtualizing是附加财产,而其对应物Grid是原生财产。不知道他们为什么选择这种差异......

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

相关链接是https://docs.microsoft.com/en-us/dotnet/api/system.windows.controls.datagrid.enablerowvirtualizationhttps://docs.microsoft.com/en-us/dotnet/api/system .windows.controls.virtualizingstackpanel.isvirtualizing