Close WPF Window From Another Window ContentRendered Event

I have 3 windows.  Window1 opens Window2 in a new thread.  It's just a window that says 'Loading'.  Window1 also opens Window3.  When Window3's ContentRendered fires I want to close Window2.

I have tried numerous things.  Why is this so difficult?  Maybe it isn't and I am just making it this difficult.

     For Each Window In Application.Current.Windows
            If Window = "Window2" Then
                Window.close()


            End If
        Next


That, of course, fails.  Can someone please tell me how to do this?  It's driving me crazy.  Thanks for any help on this.
LVL 1
G ScottAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BlueYonderCommented:
You can have a shared array or a data structure to store all active windows.  Once window 3 loads, search the structure for the window and close it.  Or the other option is to use Dispatcher.FromThread.  Check out http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.fromthread.aspx.
0
G ScottAuthor Commented:
Haha, BlueYonder...my skills are limited in WPF. I had a mistake in my code up there

 For Each win In Application.Current.Windows
            If win.Name = "winActivity" Then
                win.Close()


            End If
        Next

This works.



Disregard.  This does not work.  Haha..forgot I added a DispatcherTimer to Window2.  It was closing and I thought I had it.
0
G ScottAuthor Commented:
Application.Current.Windows.OfType(Of WindowTitle)().First().Close()

That's how you do it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
G ScottAuthor Commented:
I found the answer on my own.
0
G ScottAuthor Commented:
Took me a while, but I found the answer on my own.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.