Application Application Application Application Class

Definition

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
Inheritance
Implements

Examples

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 Microsoft.VisualBasic
Imports System
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 Microsoft.VisualBasic
Imports System.Windows

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

Remarks

Application is a class that encapsulates WPF application-specific functionality, including the following:

Application implements the singleton pattern to provide shared access to its window, property, and resource scope services. Consequently, only one instance of the Application class can be created per AppDomain.

You can implement an Application using markup, markup and code-behind, or code. 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) ApplicationDefinition item.

Note

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. However, XAML browser applications (XBAPs) require an Application object.

Constructors

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

Initializes a new instance of the Application class.

Properties

Current Current Current Current

Gets the Application object for the current AppDomain.

Dispatcher Dispatcher Dispatcher Dispatcher

Gets 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

Gets or sets the Assembly that provides the pack uniform resource identifiers (URIs) for resources in a WPF application.

Resources Resources Resources Resources

Gets or sets a collection of application-scope resources, such as styles and brushes.

ShutdownMode ShutdownMode ShutdownMode ShutdownMode

Gets or sets the condition that causes the Shutdown() method to be called.

StartupUri StartupUri StartupUri StartupUri

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

Windows Windows Windows Windows

Gets the instantiated windows in an application.

Methods

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

Determines 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)

Searches for a 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)

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)

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)

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)

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()

Gets the Type of the current instance.

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

Loads a XAML file that is located at the specified uniform resource identifier (URI) and converts it to an instance of the object that is specified by the root element of the XAML file.

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

Loads a XAML file that is located at the specified uniform resource identifier (URI), and converts it to an instance of the object that is specified by the root element of the XAML file.

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

Creates a shallow copy of the current Object.

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

Raises the Activated event.

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

Raises the Deactivated event.

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

Raises the Exit event.

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

Raises the FragmentNavigation event.

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

Raises the LoadCompleted event.

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

Raises the Navigated event.

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

Raises the Navigating event.

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

Raises the NavigationFailed event.

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

Raises the NavigationProgress event.

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

Raises the NavigationStopped event.

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

Raises the SessionEnding event.

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

Raises the Startup event.

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

Starts a Windows Presentation Foundation application.

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

Starts a Windows Presentation Foundation application and opens the specified window.

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

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()

Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)

Events

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

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 XAML 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

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

Occurs when the user ends the Windows session by logging off or shutting down the operating system.

Startup Startup Startup Startup

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

Explicit Interface Implementations

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.

Applies to

Thread Safety

The public static (Shared in Visual Basic) members of this type are thread safe. In addition, the FindResource(Object) and TryFindResource(Object) methods and the Properties and Resources properties are thread safe.

See Also