zetar
zetar

Reputation: 1233

Where can I add a method call when the MainWindow is completely built in C#

I need to call a method the first thing after the MainWindow is built. I've added this code to the XAML:

Loaded="MainWindow_Loaded"

And this method to MainWindow:

void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    SelectScenario dlg = new SelectScenario();
    dlg.Top = 22;
    dlg.ShowDialog();
    if (ScenarioSelected == true)
    {
        LoadScenarioFile(SelectedScenario);
    }
}

But the SelectScenario dialog box is being called before the MainWindow is fully built. Where can I insert the method call for the SelectScenario dialog box so I know the MainWindow has been completely built?

Upvotes: 1

Views: 127

Answers (1)

Dark Templar
Dark Templar

Reputation: 1155

There's an event called "ContentRendered" you could try this instead of loaded.

Upvotes: 5

Related Questions