c# - 如何停止/暂停已在 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# - 无法在 WPF 中创建继承的用户控件,本地命名空间中的基本控件“不存在”
- python - 从字典的值中删除标点符号和停用词
- sylius - 如何在 Sylius 1.4 中覆盖模型
- google-cloud-platform - 从 Google Cloud Run docker 映像连接到 Google Cloud SQL 实例
- html - CSS 让绝对元素重叠父级的兄弟而不影响滚动/缩放行为
- c# - ASP.NET Core 多 JWTBearer 身份验证失败
- node.js - Slack 机器人无法通过 chat.postMessage 将消息发送到受限的常规频道
- android - 如何在 Android 上使用 AsyncTask
- angular - 如何实现对一系列更新的回滚
- matlab - 模拟均值 = 1 和方差 = 0.4 的左截断 Gamma 分布