以下是我希望在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();
}
Run Code Online (Sandbox Code Playgroud)
Kev*_*lia 46
这应该工作
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
Run Code Online (Sandbox Code Playgroud)
使用System.Windows.Input不System.Windows.Forms.
小智 28
如果您的任务需要花费大量时间,而且它在非GUI线程上运行(这是一个好主意),您可以使用此代码更改应用程序游标:
Application.Current.Dispatcher.Invoke(() =>
{
Mouse.OverrideCursor = Cursors.Wait;
});
Run Code Online (Sandbox Code Playgroud)
繁忙过程完成后,使用以下命令:
Application.Current.Dispatcher.Invoke(() =>
{
Mouse.OverrideCursor = null;
});
Run Code Online (Sandbox Code Playgroud)
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
InitializeComponent();
...
Mouse.OverrideCursor = null;
Run Code Online (Sandbox Code Playgroud)