Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to close a WPF Dialog Window when the user clicks outside it

Tags:

wpf

I want to close a System.Windows.Window if the user clicks anywhere outside it. The Window is shown as a Dialogbox. How do I receive clicks outside a wpf window?

AppointmentDetailsView.ShowDialog();
like image 248
lasitha edirisooriya Avatar asked May 31 '12 07:05

lasitha edirisooriya


1 Answers

How about this?

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    protected override void OnDeactivated(EventArgs e)
    {
        base.OnDeactivated(e);
        Close();
    }
}
like image 192
sky-dev Avatar answered Oct 13 '22 08:10

sky-dev