Bagikan melalui


Application.Current Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the Application object for the current application.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Shared ReadOnly Property Current As Application
public static Application Current { get; }

Property Value

Type: System.Windows.Application
The Application object for the current application.

Remarks

Application is a singleton that implements the static Current property to provide shared access to the Application instance for the current application. The singleton pattern ensures that state managed by Application, including shared resources and properties, such as the Host information, is available from a single, shared location.

Examples

The following example shows how to get a reference to the current Application by using the Current property.

' Get a reference to the Application base class instance.
Dim currentApplication As Application = Application.Current
// Get a reference to the Application base class instance
Application currentApplication = Application.Current;

Since the Current property is inherited from the base Application class, the Current property returns a reference to the base Application object instead of the instance of the class that derives from Application. If you need direct access to the latter, you have to cast the value returned by Current to the type of the class that derives from Application. This is shown in the following code.

Run this sample

' Get a reference to the instance of the class that 
' derives from Application.
Dim currentApp As App = CType(Application.Current, App)
// Get a reference to the instance of the class that 
// derives from Application
App currentApp = (App)Application.Current;

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.