强制 TabPanel 使用指定的 TabItem 模板
因此,我创建了自己的 TabControl
和 TabItem
模板(均带有 x:Name
属性),并且像这样使用它们:
<Style TargetType="TabControl">
<Setter Property="Template" Value="{DynamicResource MyTabControl}" />
</Style>
正如预期的那样,这使得窗口中的所有 TabControl
使用 MyTabControl
模板,但它仍然使用旧的 TabItem
模板。我怎样才能让它工作,以便上面的代码以某种方式设法设置该模板内每个 TabItem
的样式以使用 MyTabItem
模板?
当然,我可以编辑 MyTabControl
模板并手动设置模板,但这需要我使用 TabPanel
容器之外的其他容器(可能是 StackPanel
>)。是否可以以某种方式告诉 TabPanel
对每个 TabItem
使用特定模板?
在 MyTabControl
中,我用它来显示 TabItem
:
<TabPanel IsItemsHost="True" />
我正在寻找类似的东西(我不知道这是否可能):
<TabPanel IsItemsHost="True" TabItemsTemplate="MyTabItem" />
So I have created my own TabControl
and TabItem
templates (both with x:Name
attribute), and I use them like this:
<Style TargetType="TabControl">
<Setter Property="Template" Value="{DynamicResource MyTabControl}" />
</Style>
As expected, this makes all TabControl
s in the window use MyTabControl
template, however it still uses the old TabItem
template. How can I make it work so the code above somehow manages to style every TabItem
inside that template to use MyTabItem
template?
Of course I could just edit the MyTabControl
template and set the template manually, but that would require me to use something else than TabPanel
container (probably StackPanel
). Is it somehow possible to tell the TabPanel
to use specific template for every TabItem
?
In MyTabControl
I use this to display TabItem
s:
<TabPanel IsItemsHost="True" />
And I'm looking for something like this (I don't know if this is possible):
<TabPanel IsItemsHost="True" TabItemsTemplate="MyTabItem" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这会起作用:
为您的 TabItem 创建一个样式,将其模板设置为您的 TabItem 模板
,并将上面的样式更改为:
您也可以忽略上面的内容并为您的 TabItem 创建一个没有键的样式,这会将所有 TabItem 设置为该样式。
您还可以在这里看看:
http://blogs.intuidev.com/post/2010/01/25 /TabControlStyling_PartOne.aspx
I believe this would work:
Create a style for your TabItem, that sets it's Template to your TabItem Template
and alter your above Style to:
You could also just ignore the above and create a style without a key for your TabItem, and this will set all TabItems to this style.
You could also have a look here:
http://blogs.intuidev.com/post/2010/01/25/TabControlStyling_PartOne.aspx