c# - 如何在 WPF 应用程序启动期间显示等待光标?

标签 c# wpf mouse-cursor

以下是我希望在我的 WPF 应用程序启动时发生的基本事件。这与 Word 在我的机器上的启动方式非常相似。

  1. 显示忙碌光标。
  2. 执行基本初始化。这需要几秒钟,并且需要在显示初始屏幕之前完成。
  3. 显示启动画面。此初始屏幕显示更深入初始化的进度,可能需要一段时间(从数据库缓存信息)。
  4. 显示默认光标。由于启动画面现在正在显示进度,因此无需显示忙碌的光标。
  5. 启动画面进度完成后,显示主窗口。
  6. 关闭启动画面。

除了在显示初始屏幕之前显示忙碌光标外,一切正常。当我通过快捷方式执行应用程序时,等待光标闪烁,但很快又恢复到默认状态。我尝试了不同的方法来设置 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/

相关文章:

objective-c - 如何观察[NSCursor currentCursor]的变化?

c# - 函数应该返回 null 还是一个空对象?

c# - MVC3 HiddenFor 与枚举。输入的值是枚举键而不是值?

c# - 测试验证 C#

c# - 有一个带有 ShowInTaskbar、Topmost 的窗口,还有一个通知区域图标

c# - 使用C#控制鼠标光标

c# - 如何以编程方式添加程序集引用?

c# - 具有绑定(bind)图像状态和悬停图像的 WPF 无 Chrome 按钮

c# - WPF 所见即所得编辑器

python - Pygame 从位图中设置鼠标光标