2
我有以下代码:TabItem - 如何更改模板并保留默认样式?
<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的默认样式 - 我指的是填充/利润率/ BorderBrush /了borderThickness,等等...这就是为什么我写BasedOn="..."
。 但它不起作用 - 我认为它会呈现与没有任何自定义样式的TabItem相同,但它不会 - 它只呈现一些文本(由ContentPresenter)。该样式不会获取默认属性值...我该如何做到这一点? 我需要我的风格在里面... ControlTemplate
这些子页面仍然不提供默认值,但提供示例。我为一个喜欢链接到[这个问题](http://stackoverflow.com/questions/1559261/control-template-for-existing-controls-in-wpf)。 – 2012-03-21 18:29:23
@ H.B。谢谢,我会尝试开始使用该答案作为默认模板问题,而不是MSDN示例。 – Rachel 2012-03-21 18:31:24