VirtualizingStackPanel 的主要缺点是什么?如果它没有任何,那么为什么它不作为 ItemsControl 中的默认面板行为/模板?
最佳答案
MSDN page在 VirtualizingStackPanel
类有以下语句:
The word "virtualize" refers to a technique by which a subset of user interface (UI) elements are generated from a larger number of data items based on which items are visible on-screen.
和
Virtualization in a StackPanel only occurs when the items control contained in the panel creates its own item containers.
和
VirtualizingStackPanel is the default items host for the ListBox element.
由此看来,对于
StackPanel
的“正常”使用作为按钮、文本块等的宿主,虚拟化不会提供任何优势,甚至可能会带来性能开销。在 ListBox
中使用时虚拟化确实有好处,因为 a) 元素容器是由元素控件创建的,并且 b) 列表中的元素可能比任何时候都可以在屏幕上显示的要多。
关于wpf - VirtualizingStackPanel 的缺点是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4051032/