tags:

views:

194

answers:

1

I have an application in which I will have to get at another WPF window which is open. In WinForms, I was able to use:

MainWindow main = (MainWindow)Application.OpenForms["MainWindow"];

To be able to access the the form. Now in WPF it does not exist. I have seen the other post on this site which is relevant, however it uses Application.Window which is not contained in the call. I just have :

  • Current
  • Equals
  • GetContentStream
  • GetCookie
  • GetRemoteStream
  • GetResourceStream
  • LoadComponet
  • RefrenceEquals
  • ResourceAssembly
  • SetCookie

So my question is this, is there a different version for OpenForms, or is there just a different way to go about it.

+1  A: 

Try looking at: Application.Current. More specifically, Application.Current.Windows.

Stephen Cleary
Thanks for the answer. Would you know how to implement it using a window name vs. a index?
Redburn
I would use LINQ: `Application.Current.Windows.OfType<Window>().Where(x => x.Name == "MainWindow").FirstOrDefault()`, which will return a window named "MainWindow" or `null` if no such window is found.
Stephen Cleary
Thanks again for the help!
Redburn