Close only one window

1

I created a window JanelaUm , every time I click on button this window is displayed.

no code-behind of JanelaUm I have event window_KeyDown with the following code:

if (e.Key == Key.Escape)
    this.Close();

However, if the user clicks 5 times on the button to display the JanelaUm , closing it using the esc key will close all 5 windows, not just one.

Would anyone have an idea how to close only one? and the other 4 remain open?

    
asked by anonymous 15.12.2014 / 16:37

1 answer

2

You can do this as follows

   if (e.Key == Key.Escape && this.IsActive)
        this.Close();
    
15.12.2014 / 17:02