为什么我的 TabControl 忽略我的 ItemsPanelTemplate?
我已经在 ListBox
等其他控件上使用了 ItemsPanelTemplate
,因此我认为对 TabControl
做同样的事情会很简单。
显然,我遗漏了一些东西,并且 TabControl
完全忽略了我在 ItemsPanelTemplate
中放置的内容。
我的 xaml 看起来有点像这样:
<TabControl TabStripPlacement="Right" ItemsSource="{Binding Components}">
<TabControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</TabControl.ItemsPanel>
</TabControl>
我尝试将 WrapPanel
替换为 UniformGrid
以查看是否存在差异并且其行为相同。我确实有一个用于 TabItem
的 ControlTemplate
,但我尝试删除它,但没有任何区别,所以我认为这不会影响我的问题。
I've used the ItemsPanelTemplate
on other controls such as the ListBox
, so I figured doing the same thing for the TabControl
would be simple.
Apparently, I'm missing something and the TabControl
is completely ignoring what I place in the ItemsPanelTemplate
.
I have xaml that looks kinda of like this:
<TabControl TabStripPlacement="Right" ItemsSource="{Binding Components}">
<TabControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</TabControl.ItemsPanel>
</TabControl>
I've tried replacing WrapPanel
with UniformGrid
to see if there was a difference and it behaves the same. I do have a ControlTemplate
for TabItem
, but I tried removing it and it made no difference so I don't think that's effecting my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能希望覆盖
Template
,而不是ItemsPanel
您可以覆盖
TabControl.ItemTemplate
(或TabItem.Template
code>) 来更改顶部选项卡的外观,TabControl.ContentTemplate
更改用于选项卡内容的模板,或TabControl.Template
更改整体模板TabControl 的。我什至不知道 TabControl 有一个 ItemsPanel。我只将其与 ItemsControl 一起使用,其中 ItemsPanel 影响包含集合中项目的控件类型。如果 TabControl 具有该属性,我希望这只是因为它从某个基类继承了它
You're probably looking to overwrite the
Template
, not theItemsPanel
You can overwrite
TabControl.ItemTemplate
(orTabItem.Template
) to alter the appearance of the Tabs along the top,TabControl.ContentTemplate
to alter the template used for the content of the Tab, orTabControl.Template
to alter the overall template of the TabControl.I wasn't even aware that TabControl's had an ItemsPanel. I've only ever used that with an ItemsControl, where the ItemsPanel affects what kind of control contains the items in the collection. If the TabControl has that property, I expect it's only because it inherited it from some base class