Search code examples
c#wpfclickwindowminimize

close a WPF Dialog Window when the user clicks outside it


GoodDay, Here i want to minimize the WPF Window, While user clicking outside of the window.

I can easily minimize the window by this code

mywindow.WindowState= WindowState.Minimized;

but i want minimize the window at the time of clicking outside of the window.

i searched about that. But i can only got the output of various events like, FocusChanged,MouseMove,MouseDown like that. those are not solve my issue


Solution

  • You could use the Deactivatedevent. Have a look at the MSDN for further information.

    A window is deactivated (becomes a background window) when:

    A user switches to another window in the current application.
    
    A user switches to the window in another application by using ALT+TAB or by using Task Manager.
    
    A user clicks the taskbar button for a window in another application.