如何延迟 windows phone 应用程序的混合故事板

How to delay in Storyboard of blend for windows phone application

我正在开发一个 windows phone 表达式混合游戏来生成随机数。问题是我想在页面加载几秒钟后启动故事板。我已经尝试实施 Timespan.FromSeconds(5) 但它没有用。我希望在计时器停止时播放故事板。我也尝试在 "if" 条件下 dispathertimer_Tick 方法启动故事板,但它也没有用。请给我建议替代方案。

 DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); 
 public MainPage()
    {
        InitializeComponent();

        dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
        dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
        dispatcherTimer.Start();
        this.Loaded += LayoutRoot_Loaded;
    }

    int count = 5;
    private void dispatcherTimer_Tick(object sender, EventArgs e)
    {          
        count--;
        if (count < 0)
        {
            dispatcherTimer.Stop();
            timer.Text = "Time Over";
            count = 5;

        }
        else
        {
            timer.Text = count.ToString();
        }

    }

    private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
    {
        expr.Text = num.Next(100).ToString();
        rectangle.BeginTime = TimeSpan.FromSeconds(5);
    }

你为什么不使用线程。

System.Threading.Thread.Sleep(5000);

// Sleep for 5 seconds
System.Threading.Thread.Sleep(new TimeSpan(0, 0, 5));

你可以做的一种方法是,你可以制作另一个页面作为你的启动页面,然后做所有这些事情。另一种方法是做那些事情,比如在 5 秒后将所有这些东西动态地插入到布局根目录中......!

如果您没有任何进展可显示,

Thread.sleep 有效。但是以一种棘手的方式,您可以每秒停止睡眠并显示进度...!

Storyboard 有一个 属性 BeginTime。只需将其设置为 5 秒即可。

在XAML中:

<Storyboard BeginTime="00:00:05" />

或 C#:

myStoryboard.BeginTime = TimeSpan.FromSeconds(5);