Application.StartupUri Property

Definition

Gets or sets a UI that is automatically shown when an application starts.

public:
 property Uri ^ StartupUri { Uri ^ get(); void set(Uri ^ value); };
public Uri StartupUri { get; set; }
member this.StartupUri : Uri with get, set
Public Property StartupUri As Uri

Property Value

Uri

A Uri that refers to the UI that automatically opens when an application starts.

Exceptions

StartupUri is set with a value of null.

Remarks

You can use StartupUri to automatically load a UI resource when an application starts.

The following table shows the types of UI resources that can be loaded, the type of window they are opened into, and the type of application that these resources can be set as the StartupUri.

Type Window Application type
Window Window Standalone only
NavigationWindow NavigationWindow Standalone only
Page NavigationWindow Standalone/browser-hosted
UserControl NavigationWindow Standalone/browser-hosted
FlowDocument NavigationWindow Standalone/browser-hosted
PageFunction<T> NavigationWindow Standalone/browser-hosted

Typically, you set the StartupUri property declaratively in XAML. However, you can set StartupUri programmatically, such as from a Startup event handler, which is useful if for applications that can only load the necessary UI resources at run time. For example, an application might wait until run time to load its resources if the name of the UI resource is stored in a configuration file.

Whether you set StartupUri declaratively or programmatically, the corresponding UI resource is not loaded until after the Startup event is handled. Consequently, you won't have access to the resulting window from either the Windows property or the MainWindow property when handling Startup.

Applies to