绑定EasingColorKeyframe值

时间:2012-01-17 09:29:48

标签: c# wpf xaml data-binding animation

我使用Expression Blend制作了一个简单的动画。问题是我无法计算如何绑定每个关键帧的值,混合不会让我这样做,并且在更改XAML后,似乎绑定剂量不能像我预期的那样工作。

这是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));

动画会起作用,但是绑定剂量不起作用,似乎颜色剂量不会通过动画改变。

感谢。

1 个答案:

答案 0 :(得分:0)

动画似乎没问题, 我会在透明背景上测试它,这样你就可以看到所有的颜色...... 此外,我无法找到每个关键帧的总持续时间和开始时间(我怀疑这是问题),但你永远不知道, 它绝对值得一试。