What is the difference between a stackpanel and a virtualizingstackpanel in WPF?

丶灬走出姿态 提交于 2019-12-12 08:19:50

问题


What is the difference between a stackpanel and a virtualizingstackpanel in WPF?


回答1:


A VirtualizingStackPanel can offer performance benefits when working with very large collections. It does so by only rendering and processing a subset of the data which is visible to the user vs. processing the entire list of data. By creating only UI elements for the visible items, this can greatly reduce the amount of work it has to do.

This is really only handy though if

  1. You are data binding non-UI elements or elements for which UI must be created in the particular panel
  2. You are data binding a lot of data

A StackPanel on the other hand, will up front create the controls for all elements contained within the StackPanel.

The VirtualizingStackPanel MSDN page has a decent discussion: http://msdn.microsoft.com/en-us/library/system.windows.controls.virtualizingstackpanel.aspx




回答2:


This is to do with the visual tree. The virtualizingstackpanel works with things like list boxes etc to reduce the size of the visual tree by only displaying visible items - this is useful where databinding is taking place.



来源:https://stackoverflow.com/questions/666108/what-is-the-difference-between-a-stackpanel-and-a-virtualizingstackpanel-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!