开发者

System.Windows.Application.OnLoadCompleted never reached

开发者 https://www.devze.com 2022-12-17 18:37 出处:网络
Hello I am trying to handle the Application.LoadCompleted event but it\'s never triggered. Instead I am seeing the MainWindow.

Hello I am trying to handle the Application.LoadCompleted event but it's never triggered.

Instead I am seeing the MainWindow.

I tried attaching the event by either xaml, or directly by overriding the OnLoadCompleted meth开发者_JAVA技巧od of the Application class.


Does your MainWindow contain a Frame?

If you read the text for the event (not the On... method), it says

Occurs when content that was navigated to by a navigator in the application has been loaded

I just tested on a Form with a Frame and the event fires just fine.


It's possible you're using the wrong event for what you want.

If you are just trying to initialize your application - perhaps to set up global messaging handlers or you can use OnStartup.

public partial class App : Application
{
    static App()
    {
        DispatcherHelper.Initialize();
    }

    protected override void OnStartup(StartupEventArgs e)
    {
        InitializeMVVM();
    }
}


It could be simply that you're attaching the event too late. i.e. after the loaded event has already fired. Show us the code...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号