WPF应用程序窗口出现在SplashScreen之上

M. *_*ley 5 wpf splash-screen

我按照如何:向WPF应用程序添加启动画面中概述的简单步骤,为我的WPF应用程序添加启动画面.当我启动应用程序时,会显示启动图像,然后弹出主窗口,并且启动图像会消失.

我的问题是,当弹出主窗口时,它会出现在初始图像的顶部.然后,当启动图像开始淡出时,启动图像会再次弹出到顶部.最终结果是,当主窗口出现时,启动图像会瞬间消失.

如何强制主窗口出现在启动图像下,以便启动图像不会消失?

Hel*_*ein 6

在.NET 4.0 中,Show方法添加了一个重载,允许在初始屏幕窗口中设置窗口样式WS_EX_TOPMOST.在代码中显示启动画面,如下所示:

SplashScreen splash = new SplashScreen("SplashScreen.png");
splash.Show(autoClose: true, topMost: true);
Run Code Online (Sandbox Code Playgroud)

我从方法中称之为

protected override void OnStartup(StartupEventArgs e)
Run Code Online (Sandbox Code Playgroud)

在App.xaml.cs.

"SplashScreen.png"当然是嵌入在应用程序资源中的splash图像的标识符.


Dan*_*iel 2

这不是默认行为,您必须有一些代码来手动聚焦主窗口吗?

使用如下代码手动关闭淡入淡出可能会更容易:

_splash = new SplashScreen("LoadingScreen.png");

_splash.Show(false);

_splash.Close(TimeSpan.Zero);