C# WPF - How to change which window opens first

Open your App.xaml file and update the StartupUri:

<Application x:Class="WpfHacking.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml"> <!-- This is the line you want to update -->
</Application>

You can also do this from the code behind by overriding the 'OnStartup' method in App.xaml.cs as below.

Do take note to remove the StartupUri="Test.xaml" from the App.xaml

protected override void OnStartup(StartupEventArgs e)
        {
            Test window = new Test();
            window.Show();
        }

Tags:

Windows

C#

Wpf