2010-08-02 106 views
0

我有一个矩形变换一个矩形的颜色,和我有一个故事板:需要在Windows Phone 7的

<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"> 

我想这种颜色的变化当按下另一个按钮出现,所以我想编程调用代码:

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

我已经把范围缩小到Storyboard.TargetName和TargetProperty在第一个片段(我认为)。我只需要帮助确定如何完成它的工作。

回答

3

想通了:

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

你必须使用(填充)(SolidColorBrush.Color)。它不喜欢(Shape.Fill)。