0

我正在使用DoubleAnimationStoryboard控制Opacity. MediaElement动画本身工作正常,但如果我打电话DisappearplayVid几秒钟后,Opacity仍然player是 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
}
4

1 回答 1

2

使用FillBehaviorequal to Stop,但也将Opacity播放器的 设置为最终的不透明度值(在Completed处理程序中)。否则,它将被重置为动画之前的值。

var fadeOut = new DoubleAnimation
{
    To = 0,
    Duration = new Duration(TimeSpan.FromMilliseconds(1000)),
    FillBehavior = FillBehavior.Stop
};

fadeOut.Completed += (s, e) =>
{
    player.Stop();
    player.Opacity = 0;
};

有关其他方法,请参阅这篇文章

于 2019-02-02T20:57:24.587 回答