Powered by MSDN

US - English
NEW! Silverlight 5 is available Learn More

How do I Style the Foreground of a TextBlock within a T... RSS

3 replies

Last post Aug 27, 2008 03:52 PM by SilverlightShow

(0)
  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

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

    Aug 26, 2008 11: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>
    
  • SilverlightShow

    SilverlightShow

    Participant

    1145 Points

    194 Posts

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

    Aug 27, 2008 02:47 PM | LINK

    Hi,

    we reproduced the problem and we also noticed, that even if the style is moved to the TabControl.Resources it does not work. May be it is a bug.

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    SilverlightShow Team,
    www.SilverlightShow.net - Silverlight and WP7 tutorials, articles, news
  • shacktoms

    shacktoms

    Member

    185 Points

    155 Posts

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

    Aug 27, 2008 03:45 PM | LINK

    Thanks for verifying that.  I thought that I may have just been doing something wrong.  I also noticed that even if the inner TextBlock is placed within a Grid, and the style is moved to Grid.Resources it still doesn't work.   It seems like maybe there is some problem either with the TabControl itself, or with the templating/storyboarding mechanism that it uses, such that the Foreground property from the template gets applied to the TextBlock.

    I will resubmit the issue as a bug.

  • SilverlightShow

    SilverlightShow

    Participant

    1145 Points

    194 Posts

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

    Aug 27, 2008 03:52 PM | LINK

    Hi,

    I already reported that as abug ;-)

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    SilverlightShow Team,
    www.SilverlightShow.net - Silverlight and WP7 tutorials, articles, news