How to Set Window Form as Startup Form in WPF Appliation

Updated on     Kisan Patel

This post will explain you how to set a Windows Form as a start up form in WPF application?

A WPF application is represented by an instance of the Application class. Application class provodes some of the essential functionalities to configure and run WPF application.

Application class allows you to control the lifetime of a WPF application.

So just open App.xaml file and remove StartupUri and write the Startup event handler Startup="Application_Startup" to App.xaml.

<Application x:Class="WPFApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Startup="Application_Startup">
    <Application.Resources>

    </Application.Resources>
</Application>

Now, open App.xaml.cs class file and define Application_Startup method as shown in below code.

public partial class App : Application
{
    void Application_Startup(object sender, StartupEventArgs e)
    {
           WindowForm window_form = new WindowForm();
           window_form.Show();
    }
}

In above code, you see we create an instance of WindowForm, and call its Show method to make it visible.

set-startup-window-wpf-app


WPF

Leave a Reply