views:

39

answers:

1

I have a rectangle, and I have a storyboard:

<Storyboard x:Key="PressAndHoldColorBar">
        <ColorAnimationUsingKeyFrames Duration="0:0:10" FillBehavior="Stop" Storyboard.TargetName="rectWarning" Storyboard.TargetProperty="Fill">
            <LinearColorKeyFrame KeyTime="0:0:0" Value="Green" />
            <LinearColorKeyFrame KeyTime="0:0:7" Value="Yellow" />
            <LinearColorKeyFrame KeyTime="0:0:10" Value="Red" />
        </ColorAnimationUsingKeyFrames>
    </Storyboard>

<Rectangle Height="100" HorizontalAlignment="Left" Margin="12,328,0,0" Name="rectWarning" Stroke="Black" StrokeThickness="1" VerticalAlignment="Top" Width="200">

I want this color change to occur when another button is pressed, so I'm trying to call the code programmatically:

s = (Storyboard)this.Resources["PressAndHoldColorBar"];
        s.Begin();

I've narrowed it down to Storyboard.TargetName and TargetProperty in the first snippet (I think). I just need help figuring out what to do to get it to work completely.

+2  A: 

Figured it out:

<Storyboard x:Name="PressAndHoldColorBar">
        <ColorAnimationUsingKeyFrames Duration="0:0:10" FillBehavior="Stop" Storyboard.TargetName="rectWarning" 
                                      Storyboard.TargetProperty="(Fill).(SolidColorBrush.Color)">
            <LinearColorKeyFrame KeyTime="0:0:0" Value="Green" />
            <LinearColorKeyFrame KeyTime="0:0:7" Value="Yellow" />
            <LinearColorKeyFrame KeyTime="0:0:10" Value="Red" />
        </ColorAnimationUsingKeyFrames>
    </Storyboard>

You have to use (Fill).(SolidColorBrush.Color). It doesn't like (Shape.Fill).

Garrison Neely