http://stackoverflow.com/questions/1924089/listbox-virtualizingstackpanel-and-smooth-scrolling-in-wpf
ItemsPanel属性需要一个ItemsPanelTemplate类型的元素,而其中必须要有一个VirtualizingStackPanel(需要Panel这个集合容器),如果某种style让它变成了普通的StackPanel,就没有virualization的功能了.
Template属性需要一个ControlTemplate元素,里面放一个WPF UI元素就行,这里我们可以直接放VirtualizingStackPanel。
两种方法都可以改变ListBox的布局(不是ListBoxItem),因为作为ItemsControl子类,有ItemsPanel这个FrameworkTemplate;作为Control的子类,又有Template(ControlTemplate类型,也是FrameworkTemplate)。
但是,第二种方法是直接改变了ListBox的Template,避免使用了默认的ItemsPresenter,ListBox本身的一些功能也会受影响,包括ItemsPanel,GroupStyle的设置,全都不再生效了–你要自己实现。第一种方式指定的ItemsPanelTemplate之所以能生效,是因为会被ItemsPresenter使用,所以必须依赖默认的ItemsPresenter的实现(在默认的ControlTemplate里)
另外,查看默认各种控件的Template的工具(利用了XamlWriter)
show me the templates,好东西。