Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if window is disposed

Tags:

wpf

I have a function in a WPF MainWindow1.Xaml when application shuts down. But in unknown cases user can close application in another way then using the "file > close" button. I just need to know in the "Closing" methode if the current MainWindow1.xaml is already disposed or not. But I could not find any property.

Can you help me?

like image 655
goldengel Avatar asked Apr 27 '11 10:04

goldengel


1 Answers

You can try

var source = PresentationSource.FromVisual(yourWindow)

If source is null or source.IsDisposed == true, that would indicate your Window has been closed.

like image 185
Samuel Jack Avatar answered Oct 11 '22 03:10

Samuel Jack