Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

    How do I Style the Foreground of a TextBlock within a TabControl

    Aug 26, 2008 10:44 PM | LINK

    The following xaml shows the problem, the Styles are successfully applied only to the TextBlocks outside the TabControl.  What is going wrong?  If I have a Style that I am using to present text consistently on a page, how do I apply that Style to the text within a TabControl?

    <UserControl x:Class="TabTextTest.Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:ctlx="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Extended"
        Width="400" Height="300">
        <StackPanel x:Name="LayoutRoot" Background="White">
            <StackPanel.Resources>
                <Style TargetType="TextBlock" x:Key="RedText">
                    <Setter Property="Foreground" Value="Red"/>
                </Style>
                <Style TargetType="TextBlock" x:Key="GreenText">
                    <Setter Property="Foreground" Value="Green"/>
                </Style>
            </StackPanel.Resources>
            <ctlx:TabControl>
                <ctlx:TabItem>
                    <ctlx:TabItem.Header>
                        <TextBlock Style="{StaticResource RedText}" Text="Red"/>
                    </ctlx:TabItem.Header>
                    <TextBlock Style="{StaticResource GreenText}" Text="Green"/>
                </ctlx:TabItem>
            </ctlx:TabControl>
            <TextBlock Style="{StaticResource RedText}" Text="Red"/>
            <TextBlock Style="{StaticResource GreenText}" Text="Green"/>
        </StackPanel>
    </UserControl>