views:

95

answers:

3

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 method of the Application class.

+1  A: 

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.

Henk Holterman
Yes, the OnLoadCompleted does actually nothing but fires the event, so it basically gives an option to handle stuff before the event-handler.
Shimmy
A: 

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...

Kent Boogaart
He does say he's tried overriding OnLoadCompleted, which couldn't be done 'too late'
Will Dean
A: 

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();
    }
}
Simon_Weaver