2012-01-17 49 views
2

我使用Expression Blend製作了一個簡單的動畫。問題在於我無法確定如何綁定每個關鍵幀的值,混合不會讓我這樣做,並且在更改XAML之後,看起來好像綁定沒有按照我預期的那樣工作。綁定EasingColorKeyframe值

這裏是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

而綁定本身沒有[errors](http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpf-or-silverlight -application.aspx)? – 2012-01-17 09:41:54

+0

我確定已選擇數據綁定警告,並且根本沒有錯誤,而不是在Blend或Visual Studio中。 – 2012-01-17 10:39:58

+1

這對我來說很好,顏色雖然看起來不長。你確定它不在那裏,對嗎? – 2012-01-17 11:03:13

回答

0

動畫似乎沒事, 我會在透明背景上測試它,所以你可以看到所有的顏色,如果有的話...... 另外我無法找到每個鍵的總持續時間和開始時間幀(我懷疑這是問題),但你永遠不知道, 其絕對值得一去。