2010-08-02 48 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)。