我可以正确设置UserControl
不透明度属性,但不能绑定到Storyboard
后。
UserControl MyControl;
MyControl.Opacity = 0.8; /// This works before animation set
Storyboard sb = new Storyboard();
DoubleAnimation opacity = new DoubleAnimation();
opacity.From = 1;
opacity.To = 0;
opacity.Duration = TimeSpan.FromMilliseconds(400);
Storyboard.SetTarget(opacity, MyControl);
Storyboard.SetTargetProperty(opacity, new PropertyPath(UserControl.OpacityProperty));
sb.Children.Add(opacity);
sb.Begin();
sb.Completed += (object sender, EventArgs e) => {
MyControl.Opacity = 0.5; /// This doesn't work anymore
}
如何在Storyboard
完成后使其有效?
答案 0 :(得分:1)
在某些情况下,您可能无法在动画制作后更改属性的值。 你可以尝试:
sb.Completed += (object sender, EventArgs e) => {
sb.Remove(MyControl);
MyControl.Opacity = 0.5;
}
原因解释为How to: Set a Property After Animating It with a Storyboard