首页 > 解决方案 > 如何停止/暂停已在 WPF 上启动的情节提要?

问题描述

我将火车图像沿铁路移动。在我的故事板中,我将开始许多动画。我想随时停止或暂停情节提要。

我尝试了很多方法来停止/暂停动画。我像下面这样开始故事板。

myStoryboard.Begin(this, true);

我的完整代码如下。

Storyboard sb;
    public mimic_screen()
    {
        InitializeComponent();
        sb = new Storyboard();

    }

    public bool move(Image target, double oldX, double oldY, double newX, double newY, int time)
    {
        try
        {

            DoubleAnimation anim1 = new DoubleAnimation(oldY, newY, TimeSpan.FromSeconds(time));

            Storyboard.SetTargetProperty(anim1, new PropertyPath("(Canvas.Top)"));

            Storyboard.SetTarget(anim1, target);

            sb.Children.Add(anim1);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Move Function Error:"+ex.Message);
            return false;
        }
        return true;
    }

    public void begin()
    {
        sb.Begin(this,true);
    }
    public void pause()
    {
        sb.Pause(this);
    }
    public void resume()
    {
        sb.Resume(this);
    }

    public void stop()
    {
        sb.Stop(this);
    }

开始功能工作清晰。但是当我调用其他函数(停止/暂停/恢复)时,什么也没有发生。当我调试时,方法成功触发。我的错误在哪里?

标签: c#wpfstoryboardcontrols

解决方案


推荐阅读