我使用 Expression Blend 制作了一个简单的动画。问题是我不知道如何绑定(bind)每个关键帧的值,混合不允许我这样做,并且在更改 XAML 之后,绑定(bind)似乎没有像我预期的那样工作。
这是 XAML:
<ColorAnimationUsingKeyFrames RepeatBehavior="Forever" Storyboard.TargetProperty="(TextElement.Foreground).(GradientBrush.GradientStops)[1].(GradientStop.Color)" Storyboard.TargetName="mainToggleButton">
<EasingColorKeyFrame KeyTime="0:0:0.2" Value="{Binding RelativeSource={RelativeSource Self}, Path=LowColor}"/>
<EasingColorKeyFrame KeyTime="0:0:0.4" Value="{Binding RelativeSource={RelativeSource Self}, Path=HighColor}"/>
<EasingColorKeyFrame KeyTime="0:0:0.8" Value="{Binding RelativeSource={RelativeSource Self}, Path=HighColor}"/>
<EasingColorKeyFrame KeyTime="0:0:1" Value="{Binding RelativeSource={RelativeSource Self}, Path=LowColor}"/>
<EasingColorKeyFrame KeyTime="0:0:1.4" Value="{Binding RelativeSource={RelativeSource Self}, Path=HighColor}"/>
</ColorAnimationUsingKeyFrames>
下面是代码后面的DependencyProperties
[Category("Flash")]
public Brush HighColor
{
get { return (Brush)GetValue(HighColorProperty); }
set { SetValue(HighColorProperty, value); }
}
// Using a DependencyProperty as the backing store for HighColor. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HighColorProperty =
DependencyProperty.Register("HighColor", typeof(Brush), typeof(AttentionControl), new UIPropertyMetadata(Brushes.LightGreen));
[Category("Flash")]
public Brush LowColor
{
get { return (Brush)GetValue(LowColorProperty); }
set { SetValue(LowColorProperty, value); }
}
// Using a DependencyProperty as the backing store for LowColor. This enables animation, styling, binding, etc...
public static readonly DependencyProperty LowColorProperty =
DependencyProperty.Register("LowColor", typeof(Brush), typeof(AttentionControl), new UIPropertyMetadata(Brushes.DarkGreen));
动画会工作,但绑定(bind)不起作用,好像颜色不会通过动画改变。
谢谢。
最佳答案
动画好像还行, 我会在透明背景上对其进行测试,这样您就可以看到所有颜色(如果有的话).... 我也无法找到每个关键帧的总持续时间和开始时间(我怀疑这是问题所在)但你永远不知道, 它绝对值得一试。
关于c# - 绑定(bind) EasingColorKeyframe 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8892234/