0

I have a small wpf/c# application and want to get a list of all of the open views. However, the Application.OpenForms, does not have "OpenForms" in the intellisense (and gives me an error). Could I be missing a specific reference of something?

I have tried: System.Windows.Application.OpenForms;

AndyDB
  • 413
  • 6
  • 22
  • Out of the many thousands of times I've seen code that uses `OpenForms`, only two of them seemed to be actually appropriate uses. If you're inclined to be using `OpenForms` more than once very couple of years, you're probably not using the right tool for the job. – Servy May 15 '14 at 17:14
  • Sorry - I am quite new to C#/WPF. What would you say would be the right way to see if a form called "viewDev" is open or not. – AndyDB May 15 '14 at 17:26
  • Whilst I understand that you may wish to mark this question as a duplicate. How about pointing users to the duplicate post (that would be much more beneficial). – AndyDB May 16 '14 at 13:17
  • There *is* a link to the duplicate post at the top of the question. – Servy May 16 '14 at 13:41
  • If you want to know if a given form is open you should generally have held onto a reference to the form from the last time you opened it so you can see if it is active or not, rather than opening the form and then keeping no record of it, thus forcing you to use `OpenForms` to try to get a hold of a reference tot he form. That's the case of virtually every use of `OpenForms` I've seen. Someone is trying to get a reference to a form that they should have simply held onto when it was created. – Servy May 16 '14 at 13:43
  • OK - Thank you. So setting up a variable to hold it would be a better way of working? – AndyDB May 16 '14 at 14:30
  • Context is important. You should likely be remembering it in some way, how will vary. – Servy May 16 '14 at 14:31

1 Answers1

2

Based on the docs for the Application class, there is no OpenForms member.

http://msdn.microsoft.com/en-us/library/system.windows.application(v=vs.110).aspx

Try Application.Windows

var openWindows = System.Windows.Application.Current.Windows;
Nathan A
  • 11,059
  • 4
  • 47
  • 63