以下是我希望在我的 WPF 应用程序启动时发生的基本事件。这与 Word 在我的机器上的启动方式非常相似。
- 显示忙碌光标。
- 执行基本初始化。这需要几秒钟,并且需要在显示初始屏幕之前完成。
- 显示启动画面。此初始屏幕显示更深入初始化的进度,可能需要一段时间(从数据库缓存信息)。
- 显示默认光标。由于启动画面现在正在显示进度,因此无需显示忙碌的光标。
- 启动画面进度完成后,显示主窗口。
- 关闭启动画面。
除了在显示初始屏幕之前显示忙碌光标外,一切正常。当我通过快捷方式执行应用程序时,等待光标闪烁,但很快又恢复到默认状态。我尝试了不同的方法来设置 Cursor,但都没有用,但我认为问题在于我不在控件/窗口中——我是在 App.xaml.cs 中进行的。而且,我设置的属性似乎是 Windows 窗体属性。这是我在 App.xaml.cs 中的代码的摘录。
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
System.Windows.Forms.Application.UseWaitCursor = true;
//System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
//System.Windows.Forms.Application.DoEvents();
Initialize();
SplashWindow splash = new SplashWindow();
splash.Show();
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
// Right now I'm showing main window right after splash screen but I will eventually wait until splash screen closes.
MainWindow main = new MainWindow();
main.Show();
}
最佳答案
这应该可行
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
使用 System.Windows.Input
而不是 System.Windows.Forms
。
关于c# - 如何在 WPF 应用程序启动期间显示等待光标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11021422/