我有一个 TabItem,我想为它定义一个模板,而不创建不同的 xaml 文件,因为我只想在选择选项卡时更改颜色渐变。我尝试将它放在 Windows.Resources 部分但它不管用..
<Style TargetType="{x:Type TabItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabItem}">
<Grid>
<Border Name="Border" Margin="10,0" BorderThickness="1,1,1,1" CornerRadius="6,6,0,0" >
<ContentPresenter x:Name="ContentSite" Height="58" Width="170" HorizontalAlignment="Center" VerticalAlignment="Center" ContentSource="Header"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF51A1CB" Offset="0" />
<GradientStop Color="#FF306886" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsSelected" Value="False">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFC3BCAE" Offset="0" />
<GradientStop Color="#FFFDCE9D" Offset="0.046" />
<GradientStop Color="#FFFFA35B" Offset="0.452" />
<GradientStop Color="#FFFF8A2C" Offset="0.461" />
<GradientStop Color="#FFFF9F30" Offset="0.724" />
<GradientStop Color="#FFFFC472" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
有人有想法吗?我将 TabControl 的定义分享给,
<TabControl HorizontalAlignment="Left" Margin="0,30,0,0" Name="tabControl1" VerticalAlignment="Top" Width="998" Grid.RowSpan="2" Height="695" >
<TabItem Height="58" Width="170" Name="tabItem1" BorderBrush="#FF27546C" BorderThickness="2" Foreground="White" FontSize="13" Margin="0" Padding="12,2" UseLayoutRounding="False">
<TabItem.Header>
<TextBlock Foreground="White" FontSize="13" TextAlignment="Center" Margin="10,0,0,0" VerticalAlignment="Center">PROFILO<LineBreak />DISCESA</TextBlock>
</TabItem.Header>....