具有自己线程的 WPF 启动屏幕被挖到其他窗口后面

发布于 2024-11-15 22:59:54 字数 1057 浏览 0 评论 0原文

在启动 WPF 应用程序时,我必须加载一些数据。这可能需要几秒钟的时间,因此我构建了一个带有文本进度文本和栏的启动屏幕。屏幕由它自己的线程运行:

public static class SplashScreen
{
     public static void ShowSplash()
     {
         if (_SplashThread == null)
         {
             _SplashThread = new Thread(() =>
                          {
                             _Splash = new WISplash();
                             _Splash.Show();
                             _Splash.Closed += (sender1, e1) => _Splash.Dispatcher.InvokeShutdown();
                             System.Windows.Threading.Dispatcher.Run();
                          });
             _SplashThread.SetApartmentState(ApartmentState.STA);
             _SplashThread.IsBackground = true;
             _SplashThread.Start();
         }
     }
}

WIsplash 的基类是Window

编辑:我必须更准确地说明: 我的启动屏幕没有相同的任务栏按钮。事实上,它根本没有按钮。我上传了一个基本项目来演示正在发生的事情: MyApp.zip

是否可以为启动屏幕提供与启动屏幕相同的任务栏按钮主窗口?

At start of my WPF application I have to load some data. This can take some seconds, so I built a splash screen with a text progress text and a bar. The screen is run by its own thread:

public static class SplashScreen
{
     public static void ShowSplash()
     {
         if (_SplashThread == null)
         {
             _SplashThread = new Thread(() =>
                          {
                             _Splash = new WISplash();
                             _Splash.Show();
                             _Splash.Closed += (sender1, e1) => _Splash.Dispatcher.InvokeShutdown();
                             System.Windows.Threading.Dispatcher.Run();
                          });
             _SplashThread.SetApartmentState(ApartmentState.STA);
             _SplashThread.IsBackground = true;
             _SplashThread.Start();
         }
     }
}

WISplash's base class is Window.

Edit: I have to state more precisely:
My splash screen does not have the same task bar button. In fact, it has no button at all. I've uploaded a basic project to demonstrate what's happening:
MyApp.zip

Is there a possibility to give the splash screen the same task bar button as the main window?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言月老 2024-11-22 22:59:54

我建议不要给启动窗口任何任务栏按钮。当您的应用程序被激活(使用事件 Application.Current.Activated)时,您可以执行以下操作:
1)使启动窗口可见
2)使启动窗口位于最上面(暂时)
3)等待一小段时间(几毫秒)
4) 使启动窗口非最顶层
这将使启动窗口在激活时弹出在所有其他窗口前面。

当您的应用程序被停用(使用事件 Application.Current.Deactivated 或 Application.Current.Exit)时,隐藏启动窗口。

我认为这应该给你你正在寻找的行为。

I would suggest not giving the splash window any taskbar button. When your app gets activated (with event Application.Current.Activated) you can do this:
1) Make the splash window visible
2) Make the splash window topmost (temporarily)
3) Wait for a short time (a few milliseconds)
4) Make the splash window non-topmost
This will make the splash window pop in front of all other windows on activation.

When your app gets deactivated (with events Application.Current.Deactivated or Application.Curent.Exit), make the splash window hidden.

I think that should give you the behavior you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文