Reputation: 925
Here's my problem : I have my first WPF window, and I create a second when changing the value of the SelectedItem of a Combobox. And I want to close the window I created when the value is changed again. I tried this :
var cCEntityWindow = new Windows.CCEntityWindow(dptList);
cCEntityWindow.CloseWindow();
from the codebehind of my first Window, but it doesn't work, so I create a simple method in my second Window :
public void CloseWindow()
{
this.Close();
}
and I call it from my first Window, but it doesn't work either, and I don't know why !
How should I do this ?
Upvotes: 0
Views: 1788
Reputation: 222582
You should call this.Close()
from the Window that you want to close, not from the other one. You could try this method, by passing the windowName
Window wintoclose = Application.Current.Windows.OfType<Window>().SingleOrDefault(w => w.Name == "Window Name");
wintoclose.Close();
Upvotes: 3