Using Multiple Windows
Using Multiple Windows
This exercise introduces how you can use multiple windows in a Windows Presentation Foundation
(WPF) application.
…and then set up the user interface for the MainWindow as shown below.
btnWindow1
btnWindow2
Content as shown
V3 3
Step 3 HCI for Windows Window1 and Window2
Set up the user interfaces for the two new windows similar to the ones below,
Each window should simply have a label to allow you to recognise which window is open.
V3 3
Build and run the application and notice what happens when you click on the top button.
Select the MainWindow design view and double click on the button btnWindow2 – this will create
the click event for you. Edit the code as shown below.
We now need to add some coding to the closing event of Window2 to re-open the MainWindow
when it is closed.
Step 5 Continued
Select the Window2 xaml file and select the Window. Now use the properties window to identify the
events that can be coded. The screen shot only shows a small number of available events.
Double click on the Closed event to create the event code outline automatically. Now edit the code
as shown below.
V3 3
Now run the program and note what happens.
Exercises
1. Add in appropriate closing events for the other two windows
2. Try creating another window and see if you can add a button to the MainWindow to open
the new Window as a normal window.
V3 3
Version history
V3 3