Application.StartupUri Application.StartupUri Application.StartupUri Application.StartupUri Property

定义

获取或设置在应用程序启动时自动显示的 UI。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

属性值

Uri引用在应用程序启动时自动打开的 UI 的。A Uri that refers to the UI that automatically opens when an application starts.

异常

注解

可以使用StartupUri在应用程序启动时自动加载 UI 资源。You can use StartupUri to automatically load a UI resource when an application starts.

下表显示了可以加载的 UI 资源的类型、打开它们的窗口的类型, 以及可以将这些资源设置为的StartupUri应用程序的类型。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

通常, 在中StartupUri XAMLXAML以声明方式设置属性。Typically, you set the StartupUri property declaratively in XAMLXAML. 但是, 您可以通过StartupUri编程方式进行设置, 如Startup事件处理程序, 如果对于只能在运行时加载必要 UI 资源的应用程序, 这会很有用。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. 例如, 如果 UI 资源的名称存储在配置文件中, 应用程序可能等到运行时加载其资源。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.

无论是以StartupUri声明方式还是以编程方式进行设置, 都不会加载相应Startup的 UI 资源, 直到处理事件。Whether you set StartupUri declaratively or programmatically, the corresponding UI resource is not loaded until after the Startup event is handled. 因此, 在处理Windows Startup时, 不能从属性MainWindow或属性访问生成的窗口。Consequently, you won't have access to the resulting window from either the Windows property or the MainWindow property when handling Startup.

适用于