c# - 具有多个 ColorAnimations 的 Silverlight Storyboard

标签 c# .net silverlight xaml storyboard

我无法弄清楚如何使用 ColorAnimation 沿可见光谱更改椭圆的填充颜色。 ColorAnimation 将颜色混合在一起,而不是沿着色谱移动,所以我想到了以下内容。

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

这是行不通的!这会导致以下错误...

Multiple animations in the same containing Storyboard cannot target the same property on a single element.

有人知道如何实现这个吗?

最佳答案

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>

我还建议尝试一下 Expression Blend,它使处理动画变得更加容易。

关于c# - 具有多个 ColorAnimations 的 Silverlight Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9912346/

相关文章:

c# - 如何将智能标记添加到我的 .NET 组件?

vb.net - 从流生成字节数组

silverlight - 如果支持 VM 的 props 的每个字段都实现 INotifyPropChange,VM 是否需要实现 INotifyPropChagned?

c# - 常规构建选项的奇怪问题

c# - 负向后视的小数或整数

c# - DataContractSerializer 和 Dictionary<string,object> 读取时失败

c# - 将带换行符的字符串输出到控制台应用程序中的文件

c# - 在一个解决方案中重定向多个项目

c# - 在调用基本构造函数之前计算值

silverlight - Silverlight 中嵌套类内的绑定(bind)属性