我有以下代码:
// 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);
问题是第一次调用函数时,动画效果很好。 第二次,不透明度属性根本不会改变。可能是什么问题呢? 在调试器中,即使在应该更改为1的行之后,.Opacity属性= 0。 然而,动画确实有效。
答案 0 :(得分:2)
除了将FillBehavior设置为Stop之外,正如您所提到的,还有其他几种方法可以确保不会发生此属性锁定:
这实际上是一个非常常见的混淆源,MSDN对此主题有decent-sized writeup。
答案 1 :(得分:1)
将答案与this question进行比较 您应该通过动画再次更改不透明度或以某种方式禁用动画。