简体   繁体   English

如何延迟混合的故事板为Windows Phone应用程序

[英]How to delay in Storyboard of blend for windows phone application

I am developing a windows phone game in expression blend that generate random numbers. 我正在开发一个表达混合的Windows手机游戏,生成随机数。 The problem is that i want to start my storyboard after certain seconds the page loaded. 问题是我想在页面加载后的几秒钟内启动我的故事板。 I have tried implementing Timespan.FromSeconds(5) but it didn't work. 我尝试过实现Timespan.FromSeconds(5)但它没有用。 I want the storyboard to be played when my timer stops. 我想在我的计时器停止时播放故事板。 Also i have tried to start storyboard in "if" condition of dispathertimer_Tick method but it too didn't work. 我也尝试在dispathertimer_Tick方法的“if”条件下启动故事板,但它也没有工作。 Please suggest me alternative for that. 请建议我替代。

 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);
    }

Why dont you use threads. 为什么不使用线程。

System.Threading.Thread.Sleep(5000);

or 要么

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

One of the way you could do is, you could make another page as your start up page and do all those things. 您可以做的一种方法是,您可以将另一个页面作为启动页面并执行所有这些操作。 another way is to do those things like after 5 seconds you insert all those things to layout root dynamically...! 另一种方法是做一些事情,比如5秒后你将所有这些东西动态地插入到布局根...

Thread.sleep works if you do not have any progress to show. 如果您没有任何显示进度,Thread.sleep可以正常工作。 but in a tricky way you could stop sleep every second and show progress...! 但是以一种棘手的方式你可以每秒钟停止睡眠并显示进度......!

Storyboard has a property BeginTime . Storyboard有一个属性BeginTime Just set it to 5 seconds. 只需将其设置为5秒。

In XAML: 在XAML中:

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

or C#: 或C#:

myStoryboard.BeginTime = TimeSpan.FromSeconds(5);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM