Application MainWindow is null in WPF (using Caliburn Micro)

mans picture mans · Sep 6, 2013 · Viewed 8.1k times · Source

I am developing a WPF application and I need to get a point to the main window of application inside a control. I am using Caliburn Micro.

Application.Current.MainWindow is null

How can I get a reference to the MainWindow of application in Caliburn Micro?

Answer

Sheridan picture Sheridan · Sep 6, 2013

That's funny, I've just answered this in another post... Try setting the Application.Current.MainWindow property in the Loaded event in the MainWindow.xaml.cs file:

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    Application.Current.MainWindow = this;
}