嗯,我有兩個問題都與動畫有關。動畫無法在Wpf中工作
1)以下代碼不會爲tittle和border設置動畫效果,我會像這樣調用以下代碼.FadeIn(),當然這是UIElement類型的。
public static void FadeIn(this UIElement targetControl)
{
DoubleAnimation fadeInAnimation = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromSeconds(1.5)));
Storyboard.SetTarget(fadeInAnimation, targetControl);
Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(UIElement.OpacityProperty));
Storyboard sb = new Storyboard();
sb.Children.Add(fadeInAnimation);
sb.Begin();
}
2)這也不起作用,沒有顯示動畫。
public static void SkewAnimation(this UIElement targetControl)
{
DoubleAnimation skewAnimation = new DoubleAnimation(0, 360, new Duration(TimeSpan.FromSeconds(3)));
Storyboard.SetTarget(skewAnimation, targetControl);
Storyboard.SetTargetProperty(skewAnimation, new PropertyPath(SkewTransform.AngleXProperty));
Storyboard sb = new Storyboard();
sb.Children.Add(skewAnimation);
sb.Begin();
}
當你說this.FadeIn(),你的意思是你是用它作爲類型的UIElement的擴展方法?那是對的嗎? – Landern 2012-08-09 16:35:37
是的,我使用這個作爲擴展方法 – Haider 2012-08-09 16:40:05