The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Application.Startup Event

Occurs when the Run method of the Application object is called.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:

public event StartupEventHandler Startup
/** @event */
public void add_Startup (StartupEventHandler value)

/** @event */
public void remove_Startup (StartupEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
<object Startup="StartupEventHandler" .../>

A typical Windows Presentation Foundation (WPF) application may perform a variety of initialization tasks when it starts up, including:

  • Processing command-line parameters.

  • Opening the main window.

  • Initializing application-scope resources.

  • Initializing application-scope properties.

You can declaratively specify the main window and application-scope resources using XAML (StartupUri and Resources, respectively). Sometimes, however, the resources or main window of your application can only be determined programmatically at run time. Additionally, application-scope properties and command-line parameters can only be used programmatically. Programmatic initialization can be performed by handling the Startup event, including the following:

  • Acquire and process command-line parameters, which are available from the Args property of the StartupEventArgs class that is passed to the Startup event handler.

  • Initialize application-scope resources by using the Resources property.

  • Initialize application-scope properties by using the Properties property.

  • Instantiate and show one (or more) windows.


Command-line parameters can also be acquired by calling the static GetCommandLineArgs method of the Environment object. However, GetCommandLineArgs requires full trust to execute.

If you set StartupUri using XAML, the main window that is created is not available from either the MainWindow property or the Windows property of the Application object until after the Startup event is processed. If you need access to the main window during startup, you need to manually create a new window object from your Startup event handler.


If your application uses CredentialPolicy to specify a credential policy, you need to set CredentialPolicy after Startup is raised; otherwise, WPF sets it to a default internal policy directly after the Startup event has been raised.

The command-line arguments that are passed to the Startup event handler are not the same as the URL query string parameters that are passed to an XAML browser application (XBAP). For an example of how to retrieve and process the latter, see URI Query String Parameters Sample.

The following example shows how to acquire and process command-line options. If the /StartMinimized command-line parameter was provided, the application opens the main window in a minimized state.

  Startup="App_Startup" />

using System.Windows; // Application, StartupEventArgs, WindowState

namespace SDKSample
    public partial class App : Application
        void App_Startup(object sender, StartupEventArgs e)
            // Application is running
            // Process command line args
            bool startMinimized = false;
            for (int i = 0; i != e.Args.Length; ++i)
                if (e.Args[i] == "/StartMinimized")
                    startMinimized = true;

            // Create main application window, starting minimized if specified
            MainWindow mainWindow = new MainWindow();
            if (startMinimized)
                mainWindow.WindowState = WindowState.Minimized;

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft