This is a migrated thread and some comments may be shown as answers.

Styling tabitem

2 Answers 185 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
Gama
Top achievements
Rank 1
Gama asked on 18 Nov 2011, 07:16 PM
I am trying to change the selected tab's background color.  I've managed to do this the following code, but when i run the project, I can't select any tabs at all.  Nothing happens when I click a tab.

<Window.Resources>
    <Style TargetType="{x:Type telerik:RadTabItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type telerik:RadTabItem}">
                    <Grid >
                        <Border
                             Name="Border"
                             Background="LightBlue"
                             BorderBrush="Black"
                             BorderThickness="1,1,1,1"
                             CornerRadius="6,6,0,0" >
                            <ContentPresenter x:Name="ContentSite"  Margin="12,2,12,2" VerticalAlignment="Center" HorizontalAlignment="Center" ContentSource="Header"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="Border" Property="Background" Value="LightBlue" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="False">
                            <Setter TargetName="Border" Property="Background" Value="LightGray" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>

2 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 23 Nov 2011, 07:32 PM
Hi Gama,

When you edit the ControlTemplate of the RadTabItem you need to keep the x:Name property of the Grid control that hosts the ControlTemplate elements of the item:
<Grid x:Name="wrapper">
    <Border x:Name="Border" Background="LightBlue" BorderBrush="Black"
            BorderThickness="1,1,1,1" CornerRadius="6,6,0,0">
        <ContentPresenter Margin="12,2,12,2"
                    HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            ContentSource="Header"/>
    </Border>
</Grid>

This name is used in the implementation logic of the control and this is why is a required part of the template of the RadTabItem. Give this a try and let us know if it works for you.

Greetings,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Richard
Top achievements
Rank 2
Veteran
answered on 27 Jan 2021, 12:47 PM

Old post I know, but I found myself asking the same question (how to change selected tab background colour) so I thought I'd share a simple solution.

<Window.Resources>
    <Style TargetType="telerik:RadTabItem" BasedOn="{StaticResource RadTabItemStyle}">
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="true">
                <Setter Property="Background" Value="White"></Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
Tags
TabControl
Asked by
Gama
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Richard
Top achievements
Rank 2
Veteran
Share this question
or