【发布时间】:2014-11-26 08:50:25
【问题描述】:
我有一个带有自定义 TabItem 样式的父 TabControl:
<TabControl ItemsSource="{Binding TabViewModels}" SelectedIndex="0" Padding="0,0,0,0" BorderThickness="0,0,0,0" Panel.ZIndex="1">
<TabControl.Resources>
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}" >
<Border Name="Border" CornerRadius="6,6,0,0" Margin="0,0,2,2">
<ContentPresenter TextBlock.TextAlignment="Center" TextBlock.FontSize="14"
Height="40" Width="auto" Content="{Binding Path=TabName}" Margin="12,2,12,2"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter TargetName="Border" Property="Background" Value="#00B6FA" />
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter TargetName="Border" Property="Background" Value="LightGray" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="TabPanel">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</TabControl.Resources>
<TabControl.ContentTemplate>
<DataTemplate>
<ContentControl Content="{Binding Path=. }"/>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
在父 TabControl 的其中一个选项卡中,我有一个子 TabControl。 问题是子 TabControl 自动采用自定义 TabItem 样式,因为如您在上面看到的那样,我覆盖了它。我想要的是子 TabControl 采用 TabItems 的默认窗口样式。 这是否可以应用自定义选项卡项而不是覆盖它并使用 ItemSource?
【问题讨论】: