Closing a child window from a parent window.


  • I am working on an application in .NET framework using WPF (Word Presentation Foundation). It complises both XAML for the GUI and C# for the code behind. I'm using Microsoft Visual Studio 2008 and Framework 3.5

    I'd like to know how to use an event in my Main or parent window to close a particular child window. For those that can help out there, my main window is call 'Main' and my child window called 'Window1'. Thanks for any information someone can provide....

    Thursday, October 22, 2009 11:17 PM

All replies

  • Window1.Close() in whatever event you want to use to close the form.

    Ron Whittle - If the post is helpful or answers your question, please mark it as such. Not As Brightly Lit
    Friday, October 23, 2009 12:21 AM
  • Hello Michael,

    The best forum for the issue here is the Windows Presentation Foundation forum. Please post thread in the right forum, I believe you will get more help.

    Thanks a lot!
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Thursday, October 29, 2009 7:35 AM
  • Hi Michael_AK,

    Create a Window1 object in class level as shown below

    Window2 win2 = new Window2();
            private void button1_Click(object sender, RoutedEventArgs e)
            private void button2_Click(object sender, RoutedEventArgs e)
    In button1 click the window object will be shown.

    You can close the opened window, by clicking button2.
    Dot Net Goodies
    My Sharepoint Blog
    Remember to click "mark as answered" when you get a correct reply to your question
    Thursday, October 29, 2009 7:55 AM