首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WPF,请教ListBox的ItemsPanel 属性

2013-08-27 
WPF,请问ListBox的ItemsPanel 属性ItemsControl.ItemsPanel 属性:MSDNItemsPanel属性值是一个ItemsPanelTe

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。

热点排行