Mahapps.metro: MetroWindow OnClosing exception (.Net 4.0)

Created on 19 Apr 2016  ·  2Comments  ·  Source: MahApps/MahApps.Metro

It is not clear why but, when I close the main window of my application, I receive an exception because the variable metroActiveDialogContainer is null.
I have checked my code and for each MetroWindow loaded I have the same OnClosing event, but when it is closed the last window I receive an additional OnClosing event where the metroActiveDialogContainer is null.

I have applied this fix (MetroWindow.cs line 782):

var dialog = this.Invoke(() => this.metroActiveDialogContainer?.Children.OfType<BaseMetroDialog>().LastOrDefault());

I have only added a Null-conditional operator (“?.”)

Probably the problem is on my side (I think that there is an hidden window that is loaded and not closed in my code) but I think that this fix can be inserted in the 'official' code.

Bug

Most helpful comment

@gigios I've added this check in a96b15de47797fca4e9f3c959695fb973696cbd8. This could happen if the window is not loaded, so the metroActiveDialogContainer is null at the closing event .

All 2 comments

@gigios I've added this check in a96b15de47797fca4e9f3c959695fb973696cbd8. This could happen if the window is not loaded, so the metroActiveDialogContainer is null at the closing event .

Very fast :)
Thanks

Was this page helpful?
0 / 5 - 0 ratings