WPF 以编程方式禁用启动画面
WPF Disable Splash Screen Programmatically
我有一个可以选择性地接受命令行参数的 WPF 应用程序。这些参数之一指定 "silent mode"(没有 UI)。如何根据此参数在启动时禁用启动画面的显示?
您应该根据您的程序参数显式创建 class SplashScreen 和 show/hide 的实例,而不是使用 SplashScreen 构建操作来生成初始屏幕。
您需要将初始屏幕图像的 Build Action 设置为 Resource 而不是 SplashScreen.
例如:
private void OnStartUp(Object sender, StartupEventArgs e)
{
if (ShowSplashScreenArgument)
{
SplashScreen splashScreen = new SplashScreen("YourSplashScreen.bmp");
splashScreen.Show();
}
// Do loading code here..
MainWindow mainWindow = new MainWindow();
if (ShowSplashScreenArgument)
{
// Close the splash..
splashScreen.Close();
}
mainWindow.Show();
}
我认为最好的方法是不要将启动画面的构建操作设置为“SplashScreen”。像这样,您可以创建自己的 SplashScreen Window 并在其上全屏显示图像,并根据一些参数显示或隐藏它。
我有一个可以选择性地接受命令行参数的 WPF 应用程序。这些参数之一指定 "silent mode"(没有 UI)。如何根据此参数在启动时禁用启动画面的显示?
您应该根据您的程序参数显式创建 class SplashScreen 和 show/hide 的实例,而不是使用 SplashScreen 构建操作来生成初始屏幕。
您需要将初始屏幕图像的 Build Action 设置为 Resource 而不是 SplashScreen.
例如:
private void OnStartUp(Object sender, StartupEventArgs e)
{
if (ShowSplashScreenArgument)
{
SplashScreen splashScreen = new SplashScreen("YourSplashScreen.bmp");
splashScreen.Show();
}
// Do loading code here..
MainWindow mainWindow = new MainWindow();
if (ShowSplashScreenArgument)
{
// Close the splash..
splashScreen.Close();
}
mainWindow.Show();
}
我认为最好的方法是不要将启动画面的构建操作设置为“SplashScreen”。像这样,您可以创建自己的 SplashScreen Window 并在其上全屏显示图像,并根据一些参数显示或隐藏它。