Application Class

July 28, 2014

Encapsulates a Windows Phone application.

System.Object
  System.Windows.Application

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public class Application
<Application .../>

The Application type exposes the following members.

  NameDescription
Public methodApplicationInitializes a new instance of the Application class.
Top

  NameDescription
Public propertyApplicationLifetimeObjectsGets the application extension services that have been registered for this application.
Public propertyStatic memberCurrentGets the Application object for the current application.
Public propertyHostGets various details about the Windows Phone application's host.
Public propertyResourcesGets a collection of application-scoped resources, such as styles, templates, and brushes.
Public propertyRootVisualGets or sets the main application UI.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodStatic memberGetResourceStream(Uri)Returns a resource file from a location in the application package.
Public methodStatic memberGetResourceStream(StreamResourceInfo, Uri)Returns a resource file from a location in the specified zip package.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberLoadComponentLoads 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.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodTerminateTerminates the current process.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventExitOccurs just before an application shuts down and cannot be canceled.
Public eventStartupOccurs when an application is started.
Public eventUnhandledExceptionOccurs when an exception that is raised by Windows Phone is not handled.
Top

Application is a class that encapsulates a Windows Phone application and provides the following services:

  • Application Entry Point

  • Application Lifetime

  • Application Management

  • Application-Scoped Resources

  • Unhandled Exception Detection

The entry point in a Windows Phone application is the class in your application assembly that derives from Application. This class is known as the application class. When the applicaton starts metadata in the application package is used to instantiate the application class. At this point, the application's lifetime starts. The lifetime of an application occurs in the following order:

Once an application is running, the Application object and its state can be accessed from the static Current property. The singleton pattern ensures that state managed by Application, including shared resources (Resources) and custom properties, is available from a single, application-scoped location.

XAML Usage Notes for the Application class

In practical XAML usage, Application is almost always the root element of the App.xaml file and therefore a practical usage would include the client and XAML xmlns values, as well as an x:Class value for the code-behind that initiates the root visual, as shown in the following XAML fragment.

<Application 
  x:Class="namespace.class"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"       
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" >
---
</Application>

Technically the XAML usage for any member of the Application class that supports XAML applies both to the Application class and also to any Application subclass that does not specifically disable XAML usage by shadowing members or changing the access level of its constructors. However, the XAML usage for Application members shows the literal Application rather than the placeholder application because subclassing Application is not necessary for most application scenarios, and the XAML usage shows the most common usage patterns whenever possible.

The following code example demonstrates how to use this class to merge the XAML and code-behind portions of a Page class. This code is similar to the InitializeComponent method that Visual Studio generates for the same purpose.

Visual Studio generates the InitializeComponent method when a XAML file has a build action of Page. To load a XAML file using the following example code, set its build action to Resource.


private System.Windows.Controls.Grid LayoutRoot;

public Page()
{
    System.Windows.Application.LoadComponent(this, new System.Uri(
        "/WindowsPhoneApp1;component/Page.xaml", 
        System.UriKind.Relative));
    this.LayoutRoot = ((System.Windows.Controls.Grid)
        (this.FindName("LayoutRoot")));
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2014 Microsoft