【发布时间】:2019-06-27 01:48:38
【问题描述】:
我正在使用DoubleAnimation 和Storyboard 来控制Opacity 的MediaElement。动画本身运行良好,但如果我在几秒钟后调用Disappear 和playVid,player 的Opacity 仍然为0!有什么问题?
public void playVid(string source, bool isMainVid)
{
player.Opacity = 1;
player.Play(); //player.Opacity is 0 here!
}
public void Disappear()
{
DoubleAnimation fadeOut = new DoubleAnimation
{
To = 0,
Duration = new Duration(TimeSpan.FromMilliseconds(1000))
};
fadeOut.Completed += (s, e) =>
{
player.Stop();
};
var storyboard = new Storyboard();
storyboard.Children.Add(fadeOut);
Storyboard.SetTargetName(fadeOut, player.Name);
Storyboard.SetTargetProperty(fadeOut, new PropertyPath(OpacityProperty));
storyboard.Begin(mainGrid, HandoffBehavior.SnapshotAndReplace); //mainGrid is player's parent
}
【问题讨论】:
-
将动画的 FillBehavior 设置为停止。
-
@Clemens Now
Opacity在动画完成时重置为动画之前的值。衰减为 0 后为 1。
标签: c# wpf storyboard opacity doubleanimation