locked
Textblock foreground ColorAnimation problem RRS feed

  • Question

  •  Hello I am trying to change the Foreground property of some textblocks but I get an error of types incompatibility.

     

    XAML code:

    <TextBlock x:Name="Item2" Text="  Preview" Grid.Column="0" Margin="-10" Grid.Row="0" FontSize="13">
                    <TextBlock.Resources>
                        <Storyboard x:Name="ColorAnimationItem2">
                            <ColorAnimation Storyboard.TargetName="Item2" Duration="00:00:01" To="#000001" Storyboard.TargetProperty="(TextBlock.Foreground)" x:Name="cai2" />
                        </Storyboard>
                    </TextBlock.Resources>
                    <TextBlock.Foreground>
                           <SolidColorBrush Color="Blue" x:Name="scb2" />
                    </TextBlock.Foreground>
    </TextBlock>

     

    C# code (into left mouse down event):

    cai2.To = Color.Green;

    ColorAnimationItem2.Begin();

     

    Error:

    ColorAnimation cannot be used to animate property Foreground due to incompatible type.

     

    Is there a problem between SolidBrushColor type and Color type into my code? I've also tried without the <TextBlock.Foreground> node, having the Foreground attribute into the main textblock node but I receive the same error.

    Wednesday, July 2, 2008 9:36 AM

Answers

  • try this instead

    <ColorAnimation Storyboard.TargetName="scb2"

    Duration="00:00:01"

    To="Green"

    Storyboard.TargetProperty="Color"

    x:Name="cai2" />

    Wednesday, July 2, 2008 9:40 AM

All replies

  • try this instead

    <ColorAnimation Storyboard.TargetName="scb2"

    Duration="00:00:01"

    To="Green"

    Storyboard.TargetProperty="Color"

    x:Name="cai2" />

    Wednesday, July 2, 2008 9:40 AM
  • I understand now, it works.

    Thank you lee_sl !

    Wednesday, July 2, 2008 9:50 AM