Nothing but .net

Different application types in WPF

With Windows Presentation Foundation coming closer to its release date with Vista almost being upon us, more and more people are taking a look at programming in WPF… Lately, people searching on Google for WPF-related information is soaring. How do you know that, you might ask? Well, in my logs, I notice a steep increase in people landing on my blog who searched for information on WPF. That’s a good thing!! ?

However, what I do notice, is that there is still some confusion on some topics.  In this article, I want to help clear out the difference between the different application types in WPF/Vista. Since this is a major change with previous application models, lots of people, including me when I first heard about it, seem confused.

So, let’s get to it!

WPF has 2 main applications models: standalone and browser. On the other hand, it also has 2 types of navigation: menu-driven, which is what we’re all used to in traditional Windows applications and link-driven, which is the default for web applications. The first thing to note is that in WPF, both types of navigation can be used in either of the application models. Neat, isn’t it?
That basically means that you can create a web application as if it were a windows application, containing a menu to navigate around. Or, create a standalone desktop application that feels like a web application, with all buttons replaced by links.
No longer are you bound to one application model with is “natural” navigation model!

Standalone applications

When you want to create a “traditional” Windows application, you should choose to create “Windows Application (WPF)”.

The Windows Form now became a Window, each of these is declared as Window1.xaml. Notice that the build action for a Window file is automatically set to Page. What this means, is that the markup is turned into a special type of resource that can be identified uniquely by a Uniform Resource Identifier (URI). This way, WPF can load the window using a URI, as is done set the starting point in your App.xaml.

<Application x:Class="WindowsApplication2.App"
    xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="Window1.xaml"
    >

This way, your application knows which window it has to load up first. This window is loaded modeless, meaning that it has no problems with you clicking anywhere else in the application.

Page’d applications

Should you want to create an application that mimics the web experience but still run as a standalone application, you should start by adding a Page(WPF).

Just like in the Window, you can add controls and content to the page. However, when you change the startupuri in the App.xaml to your newly added page, some things will change.

A window can host itself, like a form did in traditional Windows Forms programming. A HTML/ASPX page requires a browser. Now, we created a “standalone” application with the starting point set to a page. Kinda weird, right?

Well, the Application class in WPF is smart enough to detect if your startupuri is set to a page. It will then create a window to host your application.


Now, where does this “hosting window” come from?
When the startupuri is set to a XAML page or HTML page, Application  creates an instance of NavigationWindow to host them. This class derives from Window but extends it to make it look like a mini-browser window, providing navigation buttons at the top.

When content changes or when you click a link to navigate to another page, the previous content is added to the history. The management of the history itself is managed too by the NavigationWindow.

XAML Browser applications

The final type of application is the XAML browser application. While the previous type of application basically is a web application, being hosted in its own mini-browser, you can’t really take advantage of all the features modern browser have today. If that’s what you need, you should create a XAML browser application or XBAP.

To create one, you should choose new “XAML Browser Application (WPF)”. After that, you can copy all the code you created for that WPF standalone application to one or more pages, and your application is ready for the web!

One more thing you can do with XBAPs is publish them on a web- or intranet server. This is done using ClickOnce, which creates the executable along with 2 manifest files. One of these 2 has the extension XBAP, and that’s were the user navigates too. It then “downloads” the application to the local computer.

Because of the security risk, XBAPs are not installed and run in a security sandbox: some operations like writing to the registry are not allowed. Basically, XBAPs can only do things that are allowed for apps launched from the Internet zone, a restricted set of operations.

Conclusion
As you can see, the ways an application is build are different from what you are used to in traditional programming. I hope this guide is clear enough to help you choose the correct type when building a WPF application for Vista.
 


Posted on Wednesday, 11 July 2007 07:27 by gill  |  Comments (2)
Filed under:   WPF | Articles

Related posts

Comments

October 18. 2007 17:33

Merill

Super! Thanks a lot for clearing up that confusion.

Merill

November 19. 2007 15:53

alan

Hi

Looks like a good example but on my beta copy of VS2008 it would not work.

i can add a button and click event handle to pop up hello world in a messagebox but as soon as i try to add a handler for the onchange event to a textbox it blows up and gives a warning about the object not being set.

What object as it does not brake on any line of code and i can see nothing in the call stack.

arter that VS2008 goes into a loop telling me to save my work that i can not break out from.

are you using a bolt in for VS2005 to give you WPF or are you using VS2008 as i sure as hell can not get a dam thing working so be warned.

alan

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

January 7. 2009 05:54