Partager via


Windows Presentation Foundation Browser-Hosted Applications Overview

XAML browser applications (XBAPs) are intended to combine the best features of Web applications and rich-client applications. As with a Web application, XAML browser applications (XBAPs) can be deployed from a server to a system with a single click. The application then runs in the browser without any interruptions beyond the time needed to download the application. However, unlike the relatively limited graphics and media capabilities of HTML-based applications, XAML browser applications (XBAPs) have access to the rich features of the Windows Presentation Foundation (WPF) runtime.

For the most part, developing a XAML browser application (XBAP) is a matter of standard WPF programming, and is very similar to installed applications. See Building a Windows Presentation Foundation Application for a general introduction. This topic discusses aspects of implementing, debugging, and deploying that are specific to XAML browser applications (XBAPs).

This topic contains the following sections.

  • Implementing a XAML Browser Application (XBAP)
  • Deploying a XAML Browser Application

Implementing a XAML Browser Application (XBAP)

The simplest way to start a new XAML browser application (XBAP) is with Microsoft Visual Studio 2005:

  • Open Visual Studio 2005 and launch the New Project dialog box.

  • Select the WPF project type with a XAML browser application (XBAP) template.

  • Assign a project name and click OK to create the new project.

This template creates a navigation application with an application definition, App.xaml, and a single page, Page1.xaml. You can add to those as necessary. If you would prefer to use a command-line build and create your project file manually, see How to: Create a Sample Project File for a Windows Presentation Foundation XAML Browser Application.

XAML browser applications (XBAPs) need to work within the restrictions imposed by the Internet zone permission set. As a practical matter, this means that you must restrict your implementation to that subset of WPF elements that is valid with Internet zone permissions. You are also limited in how you can access system resources such as the file system and registry, and your application cannot use unmanaged code. See Windows Presentation Foundation Security for a list of valid elements. This means that any XAML browser application (XBAP) can be recompiled as an installed application, because installed applications do not have these security restrictions. Installed applications can be recompiled as XAML browser applications (XBAPs) as well, but only if they are compatible with the Internet permission set. If you attempt to exceed these permissions, your application will typically throw a security exception. The requirements include:

  • Only use the subset of WPF elements that is compatible with Internet zone permissions. See Windows Presentation Foundation Security for a list of valid elements.

  • You cannot launch additional windows or dialog boxes. You can use Popup elements, but they must stay within the bounds of the window's border.

  • Obey Internet zone restrictions on accessing system resources such as the file system or registry.

  • You cannot use unmanaged code.

You can run or debug the application from Visual Studio 2005 in exactly the same way as for an installed application. The main difference is that the application is launched in the browser instead of a stand-alone window. When you debug, your application is running in the Internet zone and will throw exceptions if you attempt to exceed those permissions.

See How to: Create a Sample Project File for a Windows Presentation Foundation XAML Browser Application for details on how to build XAML browser applications (XBAPs) from the command line.

Deploying a XAML Browser Application

When you build a XAML browser application (XBAP), the Microsoft build engine (MSBuild) typically produces three files.

  • An executable file. This contains the compiled code and has a .exe extension.

  • An application manifest. This contains metadata associated with the application and has a .manifest extension.

  • A deployment manifest. This file contains the information that ClickOnce uses to deploy the application and has an .xbap extension.

You deploy XAML browser applications (XBAPs) from a server with Microsoft Internet Information Services (IIS) or later. It is not necessary to have the WPF runtime on the server to deploy WPF applications from it. However, you do need to register the WPF Multipurpose Internet Mail Extensions (MIME) types and file extensions. See How to: Configure IIS 5.0 and IIS 6.0 to Deploy WPF Applications for details.

To prepare your XAML browser application (XBAP) for deployment, simply copy the .exe and the associated manifests to your webserver. Create a link on an appropriate Web page that navigates to the applications deployment manifest. When the user clicks the link and navigates to the .xbap file, ClickOnce automatically handles the mechanics of downloading and launching the application.