In my application I want to close a particular window when I press a button in another window manually by coding, if it is opened. How to check whether a window is opened?
Thanks in advance.
In my application I want to close a particular window when I press a
Share
You really should be keeping track of this kind of thing yourself inside of your application…
But, since it sounds like you’re not, you can lean on WPF to do it for you. It keeps track of all the open windows in your application, exposed through the
Application.Current.Windowcollection, so you can iterate through this collection looking for a match to windows of the type you’re interested in.For example: