【发布时间】:2016-12-21 04:42:33
【问题描述】:
我有以下代码:
<Window x:Class="kkk.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="tabitemstyle" TargetType="{x:Type TabItem}" BasedOn="{StaticResource {x:Type TabItem}}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<ContentPresenter x:Name="ContentSite" ContentSource="Header"></ContentPresenter>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<TabControl>
<TabItem Header="tab1" Style="{StaticResource tabitemstyle}"></TabItem>
<TabItem Header="tab1" Style="{StaticResource tabitemstyle}"></TabItem>
</TabControl>
</Grid>
</Window>
我想保留 TabItem 的默认样式 - 我的意思是 padding/margins/BorderBrush/BorderThickness 等等...这就是我写BasedOn="..." 的原因。
但它不起作用 - 我认为它会在没有任何自定义样式的情况下呈现与 TabItem 相同的效果,但事实并非如此 - 它只是呈现一些文本(通过 ContentPresenter)。该样式没有获得默认属性值......我该怎么做?
我需要 ControlTemplate 在我的风格中...
【问题讨论】:
标签: wpf tabcontrol tabitem