日期:2014-05-17  浏览次数:21125 次

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。