我用过 ItemsPanelTemplate
在其他控件上,例如 ListBox
,所以我想对 TabControl
做同样的事情会很简单。
显然,我遗漏了一些东西和 TabControl
完全无视我放在 ItemsPanelTemplate
中的内容.
我有看起来有点像这样的 xaml:
<TabControl TabStripPlacement="Right" ItemsSource="{Binding Components}">
<TabControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</TabControl.ItemsPanel>
</TabControl>
我试过更换
WrapPanel
与 UniformGrid
看看是否有区别,它的行为是否相同。我有一个 ControlTemplate
为 TabItem
,但我尝试删除它并没有任何区别,所以我认为这不会影响我的问题。
最佳答案
您可能希望覆盖 Template
,而不是 ItemsPanel
您可以覆盖 TabControl.ItemTemplate
(或 TabItem.Template
)改变顶部标签的外观,TabControl.ContentTemplate
更改用于选项卡内容的模板,或 TabControl.Template
更改 TabControl 的整体模板。
我什至不知道 TabControl 有一个 ItemsPanel。我只将它与 ItemsControl 一起使用,其中 ItemsPanel 影响包含集合中项目的控件类型。如果 TabControl 具有该属性,我希望这只是因为它从某个基类继承了它
关于wpf - 为什么我的 TabControl 忽略了我的 ItemsPanelTemplate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8172964/