WPF SplashScreen实现

Vyt*_*tas 6 wpf splash-screen

我尝试在WPF中实现Splash Screnn.我在MSDN中找到了一些很好的例子,但有一个地方:

private void _applicationInitialize(SplashScreen splashWindow)
{

    Thread.Sleep(1000);

    // Create the main window, but on the UI thread.

    Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Invoker)delegate
    {

        Window1 MainWindow = new Window1();

        Helper.setWin(MainWindow);

        MainWindow.Show();

    });

}
Run Code Online (Sandbox Code Playgroud)

问题是帮手,班级是什么以及必须如何实施.有人可以粘贴一个例子或smth?

Guy*_*Guy 12

还有一种更简单的方法:

http://msdn.microsoft.com/en-us/library/cc656886.aspx

  1. 将图像文件添加到WPF应用程序项目.有关更多信息,请参见如何:将现有项添加到项目.
  2. 在Solution Explorer中,选择图像.
  3. 在"属性"窗口中,单击"构建操作"属性的下拉箭头.
  4. 从下拉列表中选择SplashScreen


Guy*_*Guy 6

您可以使用这样的代码在启动时显示图像:

<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml" Startup="Application_Startup">
Run Code Online (Sandbox Code Playgroud)

在后面的代码中:

private void Application_Startup(object sender, StartupEventArgs e)
{
    SplashScreen screen = new SplashScreen("Images/splash.bmp");
    screen.Show(true);
}
Run Code Online (Sandbox Code Playgroud)

  • Yuor示例显示了一个闪屏,并将其打开.实际上必须在mainWindow之前显示启动画面,它必须在MainWindow出现之前自动关闭. (3认同)
  • show 方法中的布尔值被命名为 autoclose。这允许 WPF 自动处理关闭主窗口加载事件上的闪屏。 (2认同)