Need to transform a rectangle's color in Windows Phone 7

南楼画角 提交于 2019-12-25 00:42:49

问题


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.


回答1:


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).



来源:https://stackoverflow.com/questions/3390896/need-to-transform-a-rectangles-color-in-windows-phone-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!