Application Application Application Application Class

定义

封装 Windows Presentation Foundation 应用程序。Encapsulates a Windows Presentation Foundation application.

public ref class Application : System::Windows::Threading::DispatcherObject, System::Windows::Markup::IQueryAmbient
public class Application : System.Windows.Threading.DispatcherObject, System.Windows.Markup.IQueryAmbient
type Application = class
    inherit DispatcherObject
    interface IQueryAmbient
Public Class Application
Inherits DispatcherObject
Implements IQueryAmbient
继承
实现

示例

下面的示例演示如何使用仅标记定义标准应用程序:The following example shows how a standard application is defined using only markup:

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />

下面的示例演示如何使用代码仅定义标准应用程序:The following example shows how a standard application is defined using only code:

using System;
using System.Windows;

namespace SDKSample
{
    public class AppCode : Application
    {
        // Entry point method
        [STAThread]
        public static void Main()
        {
            AppCode app = new AppCode();
            app.Run();
        }
    }
}

Imports System.Windows

Namespace SDKSample
	Public Class AppCode
		Inherits Application
		' Entry point method
		<STAThread>
		Public Shared Sub Main()
			Dim app As New AppCode()
			app.Run()
		End Sub
	End Class
End Namespace

下面的示例演示如何使用标记和代码隐藏的组合定义标准应用程序。The following example shows how a standard application is defined using a combination of markup and code-behind.

<Application 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  x:Class="SDKSample.App" />
using System.Windows;

namespace SDKSample
{
    public partial class App : Application { }
}

Imports System.Windows

Namespace SDKSample
	Partial Public Class App
		Inherits Application
	End Class
End Namespace

注解

Application是一个封装WPFWPF了特定于应用程序的功能的类,其中包括:Application is a class that encapsulates WPFWPF application-specific functionality, including the following:

Application实现单独模式以提供对其窗口、属性和资源范围服务的共享访问。Application implements the singleton pattern to provide shared access to its window, property, and resource scope services. 因此,只能为每个Application AppDomain创建类的一个实例。Consequently, only one instance of the Application class can be created per AppDomain.

可以Application使用标记、标记和代码隐藏来实现,也可以使用代码来实现。You can implement an Application using markup, markup and code-behind, or code. 如果Application是通过标记实现的,无论标记、标记和代码隐藏,都必须将标记文件配置Microsoft Build Engine (MSBuild)Microsoft build engine (MSBuild) ApplicationDefinition为项。If Application is implemented with markup, whether markup or markup and code-behind, the markup file must be configured as an Microsoft Build Engine (MSBuild)Microsoft build engine (MSBuild) ApplicationDefinition item.

备注

独立应用程序不Application需要对象; 可以实现一个自定义static入口点方法(Main),用于Application打开窗口而不创建实例。A standalone application does not require an Application object; it is possible to implement a custom static entry point method (Main) that opens a window without creating an instance of Application. 但是, XAML 浏览器应用程序 (XBAP)XAML browser applications (XBAPs) Application需要对象。However, XAML 浏览器应用程序 (XBAP)XAML browser applications (XBAPs) require an Application object.

构造函数

Application() Application() Application() Application()

初始化 Application 类的新实例。Initializes a new instance of the Application class.

属性

Current Current Current Current

获取当前 ApplicationAppDomain 对象。Gets the Application object for the current AppDomain.

Dispatcher Dispatcher Dispatcher Dispatcher

获取与此 Dispatcher 关联的 DispatcherObjectGets the Dispatcher this DispatcherObject is associated with.

(Inherited from DispatcherObject)
MainWindow MainWindow MainWindow MainWindow

获取或设置应用程序的主窗口。Gets or sets the main window of the application.

Properties Properties Properties Properties

获取应用程序范围属性的集合。Gets a collection of application-scope properties.

ResourceAssembly ResourceAssembly ResourceAssembly ResourceAssembly

获取或设置为 统一资源标识符 (URI)uniform resource identifiers (URIs) 应用程序中的资源提供包WPFWPFAssemblyGets or sets the Assembly that provides the pack 统一资源标识符 (URI)uniform resource identifiers (URIs) for resources in a WPFWPF application.

Resources Resources Resources Resources

获取或设置应用程序范围资源(如样式和画笔)的集合。Gets or sets a collection of application-scope resources, such as styles and brushes.

ShutdownMode ShutdownMode ShutdownMode ShutdownMode

获取或设置导致调用 Shutdown() 方法的条件。Gets or sets the condition that causes the Shutdown() method to be called.

StartupUri StartupUri StartupUri StartupUri

获取或设置在应用程序启动时自动显示的 UI。Gets or sets a UI that is automatically shown when an application starts.

Windows Windows Windows Windows

获取应用程序中的实例化窗口。Gets the instantiated windows in an application.

方法

CheckAccess() CheckAccess() CheckAccess() CheckAccess()

确定调用线程是否可以访问此 DispatcherObjectDetermines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
FindResource(Object) FindResource(Object) FindResource(Object) FindResource(Object)

使用指定键搜索 用户界面 (UI)user interface (UI) 资源(如 StyleBrush),并在未找到所请求的资源时引发异常(请参阅 XAML 资源)。Searches for a 用户界面 (UI)user interface (UI) resource, such as a Style or Brush, with the specified key, and throws an exception if the requested resource is not found (see XAML Resources).

GetContentStream(Uri) GetContentStream(Uri) GetContentStream(Uri) GetContentStream(Uri)

返回位于指定 Uri 的内容数据文件的资源流(请参阅 WPF 应用程序资源、内容和数据文件)。Returns a resource stream for a content data file that is located at the specified Uri (see WPF Application Resource, Content, and Data Files).

GetCookie(Uri) GetCookie(Uri) GetCookie(Uri) GetCookie(Uri)

为由 Uri 指定的位置检索 Cookie。Retrieves a cookie for the location specified by a Uri.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetRemoteStream(Uri) GetRemoteStream(Uri) GetRemoteStream(Uri) GetRemoteStream(Uri)

返回位于指定 Uri 的源站点数据文件的资源流(请参阅 WPF 应用程序资源、内容和数据文件)。Returns a resource stream for a site-of-origin data file that is located at the specified Uri (see WPF Application Resource, Content, and Data Files).

GetResourceStream(Uri) GetResourceStream(Uri) GetResourceStream(Uri) GetResourceStream(Uri)

返回位于指定 Uri 的资源数据文件的资源流(请参阅 WPF 应用程序资源、内容和数据文件)。Returns a resource stream for a resource data file that is located at the specified Uri (see WPF Application Resource, Content, and Data Files).

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
LoadComponent(Object, Uri) LoadComponent(Object, Uri) LoadComponent(Object, Uri) LoadComponent(Object, Uri)

加载位于指定 统一资源标识符 (URI)uniform resource identifier (URI)XAMLXAML 文件,并将其转换为由 XAMLXAML 文件的根元素指定的对象的实例。Loads a XAMLXAML file that is located at the specified 统一资源标识符 (URI)uniform resource identifier (URI) and converts it to an instance of the object that is specified by the root element of the XAMLXAML file.

LoadComponent(Uri) LoadComponent(Uri) LoadComponent(Uri) LoadComponent(Uri)

加载位于指定XAMLXAML 处的 统一资源标识符 (URI)uniform resource identifier (URI) 文件,并将其转换为由该 XAMLXAML 文件的根元素指定的对象的实例。Loads a XAMLXAML file that is located at the specified 统一资源标识符 (URI)uniform resource identifier (URI), and converts it to an instance of the object that is specified by the root element of the XAMLXAML file.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnActivated(EventArgs) OnActivated(EventArgs) OnActivated(EventArgs) OnActivated(EventArgs)

引发 Activated 事件。Raises the Activated event.

OnDeactivated(EventArgs) OnDeactivated(EventArgs) OnDeactivated(EventArgs) OnDeactivated(EventArgs)

引发 Deactivated 事件。Raises the Deactivated event.

OnExit(ExitEventArgs) OnExit(ExitEventArgs) OnExit(ExitEventArgs) OnExit(ExitEventArgs)

引发 Exit 事件。Raises the Exit event.

OnFragmentNavigation(FragmentNavigationEventArgs) OnFragmentNavigation(FragmentNavigationEventArgs) OnFragmentNavigation(FragmentNavigationEventArgs) OnFragmentNavigation(FragmentNavigationEventArgs)

引发 FragmentNavigation 事件。Raises the FragmentNavigation event.

OnLoadCompleted(NavigationEventArgs) OnLoadCompleted(NavigationEventArgs) OnLoadCompleted(NavigationEventArgs) OnLoadCompleted(NavigationEventArgs)

引发 LoadCompleted 事件。Raises the LoadCompleted event.

OnNavigated(NavigationEventArgs) OnNavigated(NavigationEventArgs) OnNavigated(NavigationEventArgs) OnNavigated(NavigationEventArgs)

引发 Navigated 事件。Raises the Navigated event.

OnNavigating(NavigatingCancelEventArgs) OnNavigating(NavigatingCancelEventArgs) OnNavigating(NavigatingCancelEventArgs) OnNavigating(NavigatingCancelEventArgs)

引发 Navigating 事件。Raises the Navigating event.

OnNavigationFailed(NavigationFailedEventArgs) OnNavigationFailed(NavigationFailedEventArgs) OnNavigationFailed(NavigationFailedEventArgs) OnNavigationFailed(NavigationFailedEventArgs)

引发 NavigationFailed 事件。Raises the NavigationFailed event.

OnNavigationProgress(NavigationProgressEventArgs) OnNavigationProgress(NavigationProgressEventArgs) OnNavigationProgress(NavigationProgressEventArgs) OnNavigationProgress(NavigationProgressEventArgs)

引发 NavigationProgress 事件。Raises the NavigationProgress event.

OnNavigationStopped(NavigationEventArgs) OnNavigationStopped(NavigationEventArgs) OnNavigationStopped(NavigationEventArgs) OnNavigationStopped(NavigationEventArgs)

引发 NavigationStopped 事件。Raises the NavigationStopped event.

OnSessionEnding(SessionEndingCancelEventArgs) OnSessionEnding(SessionEndingCancelEventArgs) OnSessionEnding(SessionEndingCancelEventArgs) OnSessionEnding(SessionEndingCancelEventArgs)

引发 SessionEnding 事件。Raises the SessionEnding event.

OnStartup(StartupEventArgs) OnStartup(StartupEventArgs) OnStartup(StartupEventArgs) OnStartup(StartupEventArgs)

引发 Startup 事件。Raises the Startup event.

Run() Run() Run() Run()

启动 Windows Presentation Foundation 应用程序。Starts a Windows Presentation Foundation application.

Run(Window) Run(Window) Run(Window) Run(Window)

启动 Windows Presentation Foundation 应用程序并打开指定窗口。Starts a Windows Presentation Foundation application and opens the specified window.

SetCookie(Uri, String) SetCookie(Uri, String) SetCookie(Uri, String) SetCookie(Uri, String)

为由 Uri 指定的位置创建一个 Cookie。Creates a cookie for the location specified by a Uri.

Shutdown() Shutdown() Shutdown() Shutdown()

关闭一个应用程序。Shuts down an application.

Shutdown(Int32) Shutdown(Int32) Shutdown(Int32) Shutdown(Int32)

关闭将指定退出代码返回给操作系统的应用程序。Shuts down an application that returns the specified exit code to the operating system.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
TryFindResource(Object) TryFindResource(Object) TryFindResource(Object) TryFindResource(Object)

搜索指定资源。Searches for the specified resource.

VerifyAccess() VerifyAccess() VerifyAccess() VerifyAccess()

强制调用线程具有此 DispatcherObject 的访问权限。Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)

事件

Activated Activated Activated Activated

当应用程序成为前台应用程序时发生。Occurs when an application becomes the foreground application.

Deactivated Deactivated Deactivated Deactivated

当应用程序停止作为前台应用程序时发生。Occurs when an application stops being the foreground application.

DispatcherUnhandledException DispatcherUnhandledException DispatcherUnhandledException DispatcherUnhandledException

在异常由应用程序引发但未进行处理时发生。Occurs when an exception is thrown by an application but not handled.

Exit Exit Exit Exit

恰好在应用程序关闭之前发生,且无法取消。Occurs just before an application shuts down, and cannot be canceled.

FragmentNavigation FragmentNavigation FragmentNavigation FragmentNavigation

当应用程序中的导航器开始导航至某个内容片断时发生,如果所需片段位于当前内容中,则导航会立即发生;或者,如果所需片段位于不同内容中,则导航会在加载了源 XAMLXAML 内容之后发生。Occurs when a navigator in the application begins navigation to a content fragment, Navigation occurs immediately if the desired fragment is in the current content, or after the source XAMLXAML content has been loaded if the desired fragment is in different content.

LoadCompleted LoadCompleted LoadCompleted LoadCompleted

在已经加载、分析并开始呈现应用程序中的导航器导航到的内容时发生。Occurs when content that was navigated to by a navigator in the application has been loaded, parsed, and has begun rendering.

Navigated Navigated Navigated Navigated

在已经找到应用程序中的导航器要导航到的内容时发生,尽管此时该内容可能尚未完成加载。Occurs when the content that is being navigated to by a navigator in the application has been found, although it may not have completed loading.

Navigating Navigating Navigating Navigating

在应用程序中的导航器请求新导航时发生。Occurs when a new navigation is requested by a navigator in the application.

NavigationFailed NavigationFailed NavigationFailed NavigationFailed

在应用程序中的导航器在导航到所请求内容时出现错误的情况下发生。Occurs when an error occurs while a navigator in the application is navigating to the requested content.

NavigationProgress NavigationProgress NavigationProgress NavigationProgress

在由应用程序中的导航器管理的下载过程中定期发生,以提供导航进度信息。Occurs periodically during a download that is being managed by a navigator in the application to provide navigation progress information.

NavigationStopped NavigationStopped NavigationStopped NavigationStopped

在调用应用程序中的导航器的 StopLoading 方法时发生,或者当导航器在当前导航正在进行期间请求了一个新导航时发生。Occurs when the StopLoading method of a navigator in the application is called, or when a new navigation is requested by a navigator while a current navigation is in progress.

SessionEnding SessionEnding SessionEnding SessionEnding

当用户通过注销或关闭操作系统来结束 Windows 会话时发生。Occurs when the user ends the Windows session by logging off or shutting down the operating system.

Startup Startup Startup Startup

在调用 Run() 对象的 Application 方法时发生。Occurs when the Run() method of the Application object is called.

显式界面实现

IQueryAmbient.IsAmbientPropertyAvailable(String) IQueryAmbient.IsAmbientPropertyAvailable(String) IQueryAmbient.IsAmbientPropertyAvailable(String) IQueryAmbient.IsAmbientPropertyAvailable(String)

查询当前范围中是否有指定的环境属性。Queries for whether a specified ambient property is available in the current scope.

适用于

线程安全性

此类型staticShared公共(在 Visual Basic)成员是线程安全的。The public static (Shared in Visual Basic) members of this type are thread safe. 此外, FindResource(Object)TryFindResource(Object)方法以及PropertiesResources属性都是线程安全的。In addition, the FindResource(Object) and TryFindResource(Object) methods and the Properties and Resources properties are thread safe.

另请参阅