我有以下代码:WPF - Opacity属性不起作用第二次
// Fade out the photo, and after, fade in canvas
double DurationSeconds = duration.TimeSpan.TotalSeconds;
System.Windows.Media.Animation.Storyboard storyboard = new System.Windows.Media.Animation.Storyboard();
System.Windows.Media.Animation.DoubleAnimation animScreenshot = new System.Windows.Media.Animation.DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(DurationSeconds/3)));
System.Windows.Media.Animation.Storyboard.SetTargetName(animScreenshot, DrawingCanvasTransition.Name);
System.Windows.Media.Animation.Storyboard.SetTargetProperty(animScreenshot, new PropertyPath(Image.OpacityProperty));
// !!!
RectangleTransition.Opacity = 1; // <----------------- PROBLEM IS HERE
RectangleTransition.UpdateLayout();
System.Windows.Media.Animation.DoubleAnimation animRect = new System.Windows.Media.Animation.DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(DurationSeconds/3)));
animRect.BeginTime = TimeSpan.FromSeconds(DurationSeconds * .66);
System.Windows.Media.Animation.Storyboard.SetTargetName(animRect, RectangleTransition.Name);
System.Windows.Media.Animation.Storyboard.SetTargetProperty(animRect, new PropertyPath(Rectangle.OpacityProperty));
storyboard.Children.Add(animScreenshot);
storyboard.Children.Add(animRect);
// And start!
storyboard.Begin(this);
的问题是,第一次函数调用,动画完美的作品。 第二次,不透明属性根本没有改变。可能是什么问题呢? 在调试器中,.Opacity属性= 0,即使在应该更改为1的行之后。 然而,动画确实有效。
RectangleTransition是否有与之相关的画笔,以便确实更改颜色的不透明度? – 2011-02-10 15:47:24