Charles Petzold



Web Browser Apps

February 24, 2006
NYC

It's likely that most WPF applications will be compiled into .EXE files, just as with previous Windows APIs. As you probably know, WPF also allows running "loose XAML" files. These XAML files cannot have a root element of Window — generally a panel or Page is used instead — and they can't have any event handlers or require any procedural code. Loose XAML files appear to run inside Internet Explorer courtesy of a program named PresentationHost.exe.

Between these two extremes is something referred to as the "Web Browser Application" or the "WinFX XAML Browser Application." These applications are compiled from code and XAML and have a filename extension of .XBAP. (That's a terrible extension, I know. In earlier manifestations of Avalon, the filename extension was .XAPP, which would have allowed us to refer to them as "zap files." Alas, we now have to call them "ex baps.")

Web Browser Apps run inside IE, much like loose XAML. They cannot create objects of type Window, which means no custom dialog boxes. They are partial-trust applications, which means they can't do file I/O. On the up side, if you have the WinFX runtime components installed, executing one of the apps over the Internet is fairly seamless. Web Browser Apps create their own little navigation buttons at the upper-left corner of IE's client area and support page-oriented navigation.

As an example, here is a Browser App named JeuDeTackquin.xbap, a game also known as the 14-15 puzzle. If you have the February CTP installed, Internet Explorer should load this just fine. (How well your RSS aggregator loads it probably depends on the extent to which it uses IE.) The program is also runnable from the WPF book page of my web site.

I adapted the source code for this app from a program in a fairly early chapter of my forthcoming WPF book. The original version used a Window of course, and hard-coded the row and column dimensions as const integers. As I was modifying the code (basically changing from a Window to a Page and moving the layout to XAML) it occurred to me that I could easily implement a button to create a new instance of the Page, change the row and column dimensions, and then navigate to that page. It became a cheap and easy way to start with a 4x4 grid, but then move to 5x5, 6x6, and so forth. Each of the pages maintains state and you can navigate back and forth between them.

Interesting how a change in paradigm suggested an application option that wouldn't have occurred to me otherwise. (Or maybe that's to be expected.)