【问题标题】:Automatically redirecting to another xaml page after 5 seconds5 秒后自动重定向到另一个 xaml 页面
【发布时间】:2016-04-21 09:19:45
【问题描述】:

我正在开发一个 Windows Phone 8.1 应用程序。我想知道如何在 5 秒后重定向到另一个 xaml 页面。 我想执行以下操作: 当我单击注销按钮时,它应该导航到另一个页面(我可以很容易地做到这一点)但我想要的是该页面不应显示超过 5 秒,它应该在 5 秒后导航到其他特定页面.

【问题讨论】:

  • 当您单击注销按钮时启动计时器。 5 滴答后进行导航。
  • @LovetoCode 实际上我不知道使用 Timer,因为我是开发新手。你能帮忙吗?
  • 好的。我会发布答案
  • @LovetoCode 非常感谢。

标签: c# xaml windows-phone-8.1


【解决方案1】:
    using System.Threading.Tasks;

    //...

    private async void LogOut()
    {
        await Task.Delay(5000); //wait for 5 seconds asynchronously 
        //TODO: perform navigate
    }

【讨论】:

    【解决方案2】:
     DispatcherTimer timer;
            private void button_Click(object sender, RoutedEventArgs e)
            {
                if (timer == null)
                {
                    timer = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(5) };
                    timer.Tick += Timer_Tick;
                    timer.Start();
                }
            }
     private void Timer_Tick(object sender, object e)
            {
                timer.Stop();
                Frame.Navigate(typeof(MainPage));//Give your page here
            }
    

    【讨论】:

    • 我的错,它对我不起作用。我认为 RavingDev 提供的解决方案非常简单直接,并且对我有用。
    • @AmanshuKataria 我没有添加代码来启动计时器。更新了我的答案。这应该有效。我同意其他答案很简单。我发布了这个答案作为另一种方式。它也没有那么复杂。你可以选择任何你想要的。
    猜你喜欢
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 2014-09-02
    • 2012-08-11
    • 2015-03-09
    • 2019-11-21
    • 2013-09-05
    • 2017-06-08
    相关资源
    最近更新 更多