10秒后重定向到新的wpf窗口 [英] redirect to a new wpf window after 10 seconds
问题描述
如何在10秒后重定向到新的wpf窗口?我正在尝试将windows.hide()用于当前窗口,将windows.show()用于另一个窗口,但这不起作用。
我写下面的代码...
我想在10秒后从MainWindow重定向到Window1。
How to redirect to a new wpf window after 10 seconds?I am trying to use windows.hide() for current window and windows.show() for another window but this doesn't work.
I wrote the code below...
I want to redirect from MainWindow to Window1 after 10 seconds.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace UIPack
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
Window1 w = new Window1();
InitializeComponent();
System.Threading.Thread.Sleep(10000);
this.Hide();
w.Show();
}
}
}
但是在上面的情况下,MainWindow根本没有出现Window1在10秒后出现
But in the case above the MainWindow doesnt appear at all and Window1 appears after 10 seconds
推荐答案
等待10秒很容易,特别是如果你想要Thread.Sleep(根据你上面的代码)的行为(但更好) ,通过调用你的函数等的计时器实现,以便用户或应用程序可以在那10秒内执行操作。
将DispatcherTimer限制为仅一次,您可以在dispatcherTimer_Tick中添加此代码:
Waiting 10 seconds is easy, especially if you want the Thread.Sleep (as per your code above) sort of behaviour (but better yet, achieved via a timer that will call your function etc, so that the user or the application can perform actions in those 10 seconds).
to limit the DispatcherTimer to only once, you can add this code in dispatcherTimer_Tick:
(sender as DispatcherTimer).Stop();
现在,切换WPF窗口 - 请参阅以下Q& A,其中显示了HowTo:
how-to-switch-wpf-windows [ ^ ]
干杯,
Edo
Now, switching the WPF window - see the following Q&A that shows HowTo:
how-to-switch-wpf-windows[^]
Cheers,
Edo
这篇关于10秒后重定向到新的wpf窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!