Chapter 2. Applications and Settings

A WPF application is a Windows process in which you have an instance of the WPF Application object. The Application object provides lifetime services and integration with ClickOnce deployment. Between application sessions, you'll want to be able to keep application and user settings in a way that integrates well with WPF applications. All of these topics are the focus of this chapter.

On the other hand, if you're interested in XML Browser Applications (XBAPs)—applications hosted in the browser and deployed over the Web—read Chapter 11.

Application Lifetime

In the Windows sense, an "application" is an address space and at least one thread of execution (a.k.a. a "process"). In the WPF sense, an application is a singleton object that provides services for UI components and UI programmers in the creation and execution of a WPF program. More specifically, in WPF, an application is an instance of the Application class from the System.Windows namespace.

Explicit Application Creation

Example 2-1shows code for creating an instance of the Application class.

Example 2-1. Creating an application explicitly

using System;
System.Windows; // the home of the Application class

class Program {
    [STAThread]
    static void Main(  ) {
        Application app = new System.Windows.Application(  );
        Window1 window = new Window1(  );
        window.Show(  );
        app.Run(  );
    }
}

Here, we're creating an application inside an STA thread,[5] creating a window and showing it, and then running the application. ...

Get Programming WPF, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.