读书人

WPF请教ListBox的ItemsPanel 属性

发布时间: 2013-08-27 10:20:47 作者: rapoo

WPF,请问ListBox的ItemsPanel 属性
ItemsControl.ItemsPanel 属性:MSDN
ItemsPanel属性值是一个ItemsPanelTemplate。
而后面又说的:对于 ListBox,默认ItemsPanelTemplate指定了VirtualizingStackPanel。
但VirtualizingStackPanel并非继承自ItemsPanelTemplate啊,而且也不是继承自FrameworkTemplate啊
[解决办法]
MSDN中的意思是,放在ItemsPanelTemplate中的必须是一个Panel(有且仅能有一个),而VirtualizingStackPanel就是继承自Panel的,看msdn上的继承图:

引用
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Media.Visual
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Panel
System.Windows.Controls.VirtualizingPanel
System.Windows.Controls.VirtualizingStackPanel

如果你自己定义ItemsPanelTemplate的话,可以把VirtualizingStackPanel换成其它Panel,如你给出的链接中的例子中的StackPanel。

读书人网 >C#

热点推荐