Beta VAP
Beta VAP

Reputation: 1

How to close WPF User Control window

I have a question about closing a User Control Window.

In this application the main window will have a button to open the User control Window. In the User Control Window there are two buttons: one is to save and the other is to cancel. In the cancel click event, the user control alone needs to get closed and get back to the main window.

This code is closing the main window, too.

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
    var mywindow = Window.GetWindow(this);
    mywindow.Close();
}

Upvotes: 0

Views: 2531

Answers (1)

The Moon
The Moon

Reputation: 87

Can you try:

private void btnCancel_Click(object sender, RoutedEventArgs e)
    {
        var mywindow = Window.GetWindow(this);
        this.Close();
    }

I guess mywindow is your main window

Upvotes: 2

Related Questions