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));
動畫的工作,但結合量不行,它好像顏色劑量通過動畫不會改變。
謝謝。
而綁定本身沒有[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
我確定已選擇數據綁定警告,並且根本沒有錯誤,而不是在Blend或Visual Studio中。 – 2012-01-17 10:39:58
這對我來說很好,顏色雖然看起來不長。你確定它不在那裏,對嗎? – 2012-01-17 11:03:13