views:

71

answers:

1

In the program I am trying to build, I have a menu button that opens a second window. The user puts information into the second window, presses the "Done" button, and the information is transfered into the main window. The problem I am having is opening the second window. I have both windows build in xaml files in Visual Studio but I can't find a way to show the second window. Using "Window window = new Window" does not fit my needs because 1) I already have the second window built and 2) I have tried this and I cannot figure out how to add children to the window; there is no window.children nor any grid to put the children into. Thank you in advance!


Moments after I pressed post, I thought of something I hadnt tried:

"WindowAdd add = new WindowAdd; //WindowAdd being the second window

add.Show();"

This does exactly what I want it to do. The next problem I have is sending the information the TextBoxes into the MainWindow. I am thinking cookies might work but am unsure. Anyone have any thoughts? Thanks in advance!

+2  A: 

You need to create the Window in code, but instead of doing:

Window window = new Window();

You should use:

Window2 window = new Window2(); // Assuming the window's class name is Window2

This will construct and initialize an instance of your new window class, defined in XAML. Once you've done this, you can open the window and you'll see all of your controls.

Reed Copsey
Thank you for your answer. This information would have saved me a lot of time if only I had received it sooner.
Daniel