views:

102

answers:

2

How can I add an window/event listener/handler to a wpf-window? I want to know, if the user wants to close the window.

+1  A: 

You can subscribe to the Closing event of your Window. You can cancel the action using the EventArgs (and its Cancel property)

Jalfp
+1  A: 

You can override OnClosing inside the Window.xaml.cs.

winSharp93
Where can i find the Window.xaml.cs-file?
elr
The actual name depends on the name of the XAML file (they are both generated when adding a WPF Window). It will be [Windowname].xaml.cs
winSharp93