0% found this document useful (0 votes)
11 views

Show Multiple Windows at Startup in WPF

This document discusses how to show multiple windows when a WPF application starts. It explains that by default, only one window specified in StartupUri will open. To open additional windows, an event handler can be added to the App startup event. The event handler instantiates and shows the additional windows by setting their position properties and calling Show. This allows multiple windows to open at startup.

Uploaded by

Abhi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Show Multiple Windows at Startup in WPF

This document discusses how to show multiple windows when a WPF application starts. It explains that by default, only one window specified in StartupUri will open. To open additional windows, an event handler can be added to the App startup event. The event handler instantiates and shows the additional windows by setting their position properties and calling Show. This allows multiple windows to open at startup.

Uploaded by

Abhi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Show multiple Windows at startup in WPF

There are often times when you need to show multiple Windows when a WPF application starts. When you create a WPF application, your App.xaml looks like this. As you can see from this XAML code, the StartupUri is set to Window1.xaml. That means, when your application runs, Window1.xaml is the first Window that is shown. <Application x:Class="WPFSample.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml" > <Application.Resources>

</Application.Resources> </Application> Now let's say, you have one more window called SecondWindow.xaml. You want both of these Windows to be shown when the application starts. This can be achieved by calling SecondWindow on the application startup event. To write the startup event handler, I add Startup="App_Startup" to App.xaml. <Application x:Class="WPFSample.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml" Startup="App_Startup"> <Application.Resources>

</Application.Resources> </Application>

Now I write this event handler in the App class and create an instance of SecondWindow, set its position by using Top and Left properties and call its Show method to make it visible. public partial class App : Application { void App_Startup(object sender, StartupEventArgs e) { SecondWindow mainWindow = new SecondWindow(); mainWindow.Top = 100; mainWindow.Left = 400; mainWindow.Show(); } } Now if you run the application, you will see two Windows.

Using the same approach, you can show as many Windows you would like on the application startup.
Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.

You might also like