简体   繁体   English

SplashScreen实施后未加载WPF资源

[英]WPF Resources aren't loaded after SplashScreen implementation

i wanted to implement a splashscreen in my wpf application, where i can show some status messages. 我想在我的wpf应用程序中实现启动画面,在其中可以显示一些状态消息。 I found a good tutorial on how to do it. 我找到了一个很好的教程。

I'm using mvvm toolkit. 我正在使用mvvm工具包。 My App.xaml has the StartupUri set to "View/Shell.xaml". 我的App.xaml将StartupUri设置为“ View / Shell.xaml”。 This all works fine. 这一切都很好。 Now I want to start the Splashscreen before the StartupUri is "called". 现在,我想在“调用” StartupUri之前启动启动画面。

In the App.xaml.cs I implemented the main method like this: 在App.xaml.cs中,我实现了以下主要方法:

[STAThread()]
    static void Main()
    {
        Splasher.Splash = new IPA.Merlin.View.ViewSplashScreen();
        Splasher.ShowSplash();

        for (int i = 0; i < 1000; i++)
        {
            MessageListener.Instance.ReceiveMessage(string.Format("Load module {0}", i));
            Thread.Sleep(1);
        }

        new App();
    }
    /// <summary>
    /// 
    /// </summary>
    public App()
    {
        StartupUri = new System.Uri("View/Shell.xaml", UriKind.Relative);

        Run();
    }

For this to run i had to change the startupobject in project prefs to this main method. 为此,我必须将项目偏好设置中的startupobject更改为该主要方法。

So now my Splashscreen gets called and shows the test messages and after this App() is called. 所以现在我的Splashscreen被调用并显示测试消息,并且在调用此App()之后。 I get the following error: Provide value on 'System.Windows.StaticResourceExtension' threw an exception with inner error : "Resource with the name {Locator} cannot be found 我收到以下错误:在'System.Windows.StaticResourceExtension'上提供值引发了内部错误异常:“找不到名称为{Locator}的资源

If I change the StartupUri to another Window, this windows resources also aren't found. 如果我将StartupUri更改为另一个窗口,则也找不到该Windows资源。 This occours only if i change the startupobject and then call app.run myself. 仅当我更改启动对象然后自己调用app.run时,这种情况才会发生。 Without the Splashscreen all Resources are found without problems. 没有启动画面,所有资源都不会出现问题。

Can anyone help me with this because it's making me crazy 谁能帮助我,因为这让我发疯

Thanks in advance 提前致谢

Instead of creating Main() method, you can override OnStartup method which gets called before main window gets initialized (App.xaml.cs) - 除了创建Main()方法,您还可以override OnStartup方法,该方法before main window gets initialized (App.xaml.cs)被调用before main window gets initialized (App.xaml.cs) -

protected override void OnStartup(StartupEventArgs e)
{
   base.OnStartup(e);

   Splasher.Splash = new IPA.Merlin.View.ViewSplashScreen();
   Splasher.ShowSplash();

   for (int i = 0; i < 1000; i++)
   {
      MessageListener.Instance.ReceiveMessage(string.Format("Load module {0}", i));
      Thread.Sleep(1);
   }

   Splasher.CloseSplash();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM