Compartilhar via


Application Constructor

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

Initializes a new instance of the Application class.

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

Syntax

'Declaration
Public Sub New
public Application()

Remarks

If your application class is implemented entirely using code, you must register a handler with the Startup event in the constructor. You can optionally register handlers with the other Application class events in the constructor, including Exit and UnhandledException.

If your application class is implemented using markup and code-behind, you should register your events in markup and call InitializeComponent from the constructor to ensure that your events are hooked up, and any properties you set in markup are applied.

Examples

The following code shows the minimum application class implementation in markup and code-behind that calls InitializeComponent.

<Application xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="SilverlightApplication.App">

</Application>
Partial Public Class App
    Inherits Application

    Public Sub New()
        ' Initialize custom properties and events.

        ' Merge application class markup implementation with 
        ' this object.
        InitializeComponent()
    End Sub

End Class
using System.Windows; // Application

namespace SilverlightApplication
{
    public partial class App : Application
    {
        public App()
        {
            // Initialize custom properties and events.

            // Merge application class markup implementation with 
            // this object.
            InitializeComponent();
        }
    }
}

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.