How to Start a WPF application programmatically?

Run method of Application class in WPF is used to starts an application.

The code snippet in Listing 1 creates an Application instance and calls Run method.

Application app = new Application ();

app.Run();

Listing 1

 Run method can also take a Windows instance as a parameter and the passed instance Windows is the startup window.

The code snippet in Listing 2 creates an Application instance and calls Run method and pass a Window object as a parameter.

Application app = new Application ();

app.Run(new Window1());

Listing 2