c# - 绑定(bind) EasingColorKeyframe 值

标签 c# wpf xaml data-binding animation

我使用 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/

相关文章:

c# - 如果按住鼠标左键而不移动光标,Window.DragMove() 会导致窗口暂时卡住

c# - 按钮 IsEnabled 永远不会改变

c# - 在 C# 中如何获取网格中单元格的内容?

c# - Moq Xunit 测试设置以在 C# 中返回 IDictionary

c# - 如何获得 Windows 10 强调色?

单击“保存”按钮后的 WPF 数据绑定(bind)

c# - 更新数据源时 ListBox 不刷新 SelectedItem 并且新源具有与 'equals' SelectedItem 不同的对象

c# - 如何计算 WPF 绑定(bind)中的值

c# - .NET 实现的 scrypt

c# - EF Core Sqlite 中的 Linq 查询不起作用