TabItem的模板

时间:2012-10-10 11:01:32

标签: xaml background tabitem

我有一个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>....

1 个答案:

答案 0 :(得分:0)

问题在于您的控件模板。您可以使用这样的资源。

<Style TargetType="{x:Type TabItem}">
        <Style.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>
        </Style.Triggers>
    </Style>

我不知道您为什么要编辑ControlTemplate。

仅供参考,您的xaml看起来很复杂。应该很简单。

干杯..