2012-03-28 38 views
1

我在使用ColorAnimation改变沿着可见光谱颜色的椭圆的填充颜色时遇到了困难。 ColorAnimation将颜色混合在一起,而不是沿着色谱移动,所以我想出了以下内容。带多个ColorAnimations的Silverlight情节串联板

<Ellipse x:Name="indicatorEllipse" HorizontalAlignment="Right" VerticalAlignment="Center" Height="20" Width="20" Stroke="Black" Margin="0 0 5 0" > 
<Ellipse.Resources> 
    <Storyboard x:Name="indicatorStoryboard"> 
     <!-- Animate the fill color of the Ellipse from red to green over 100 seconds. --> 
     <ColorAnimation BeginTime="00:00:00" Storyboard.TargetName="indicatorColorBrush" 
Storyboard.TargetProperty="Color" 
From="Red" To="OrangeRed" Duration="0:00:14" /> 
     <ColorAnimation BeginTime="00:00:15" Storyboard.TargetName="indicatorColorBrush" 
Storyboard.TargetProperty="Color" 
From="OrangeRed" To="Orange" Duration="0:00:14" /> 
     <ColorAnimation BeginTime="00:00:30" Storyboard.TargetName="indicatorColorBrush" 
Storyboard.TargetProperty="Color" 
From="Orange" To="Yellow" Duration="0:00:30" /> 
     <ColorAnimation BeginTime="00:01:01" Storyboard.TargetName="indicatorColorBrush" 
Storyboard.TargetProperty="Color" 
From="Yellow" To="YellowGreen" Duration="0:00:14" /> 
     <ColorAnimation BeginTime="00:01:16" Storyboard.TargetName="indicatorColorBrush" 
Storyboard.TargetProperty="Color" 
From="YellowGreen" To="GreenYellow" Duration="0:00:14" /> 
     <ColorAnimation BeginTime="00:01:31" Storyboard.TargetName="indicatorColorBrush" 
Storyboard.TargetProperty="Color" 
From="GreenYellow" To="Green" Duration="0:00:14" /> 
    </Storyboard> 
</Ellipse.Resources> 
<Ellipse.Fill> 
    <SolidColorBrush x:Name="indicatorColorBrush" Color="Red" /> 
</Ellipse.Fill> 

不工作!这会导致以下错误...

在同一个包含Storyboard的多个动画不能将单个元素上的相同属性设为 。

任何人都有如何完成这个想法?

+0

我创建了多个故事板,并为每个故事板添加了一个Completed处理程序,以便从一个转换切换到另一个转换,但这不可能是最佳解决方案? – antwarpes 2012-03-28 17:41:44

回答

5

ColorAnimationUsingKeyFrames将解决你的问题:

<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="Color" Storyboard.TargetName="indicatorColorBrush"> 
    <SplineColorKeyFrame KeyTime="0:0:2" Value="OrangeRed"/> 
    <SplineColorKeyFrame KeyTime="0:0:4" Value="Orange"/> 
    <SplineColorKeyFrame KeyTime="0:0:6" Value="Yellow"/> 
</ColorAnimationUsingKeyFrames> 

我也sugest给的Expression Blend一个尝试,它与动画工作的一个很好的协议更容易。

+0

啊!我怎么错过ColorAnimationUsingKeyFrames? TY! – antwarpes 2012-03-29 14:18:23