Windows Presentation Foundation: From a XBAP to an EXE

.NET, Technical stuff, WPF
See comments
I spent most of the day studying the project properties of WPF applications, both Standalone and Browser applications, and comparing them. The goal is to find out what are the minimal changes you have to apply to a project in order to run an application in the browser, or outside of it.
(For those who don't know, WPF applications can run using Internet Explorer as a host (XAML Browser Applications, XBAP), or standalone as a regular EXE. For XBAP, restricted permissions apply (sandbox), and of course the navigation model is different (Pages instead of Windows)).
It was quite a tiring task, but I think I managed to understand more or less what every property in the CSPROJ file does and to extract the minimal changes needed in order to run the XBAP as standalone.
  1. Create a WinFx Web Browser Application
  2. Close the solution
  3. Open the CSPROJ file in a text editor
  4. Set "HostInBrowser" to false
  5. Set "Install" to true
  6. Delete the tags: "StartAction", "StartProgram", "StartArguments" tag
  7. Open the project file in VS2005
  8. Replace the Page tag with a Window tag in the XAML file
  9. Replace the Page base class with Window base class in the CS file
  10. Build the project and execute
I must be honest, I am not really sure what this proves. I am really not sure that using exactly the same code base for the Windows and the Web scenario is a possible choice. After all, the navigation model is very different, but more importantly, in the web case, you have a distributed environment (client-server). So what does it mean for the Windows application? If the "client" part has to communicate with the "server" part using Web Services only because of the constraints set by the Web scenario, isn't it too much of a hassle for a Windows app? Isn't it too slow?
Also, how would one handle the permission problems? Ideally, the application should react the same if it runs standalone or in the browser. However, if the permissions are not carefully evaluated, the XBAP won't even install, especially if it runs in the Internet zone. So should you always choose the "lesser permissions" scenario, just to be safe? Is it really worth going through all that?
Or should we just follow the "two ways" model (one Windows application and one Web application, separate requirements, separate deployment, separate application model, separate teams...)?
Previous entry | Next blog entry

Responses to “Windows Presentation Foundation: From a XBAP to an EXE”

  1. Bogdan Says:

    I found it is not necessary to replace the <Page></Page> tags with <Window></Window> tags, or change the base class. This creates a navigator for your page, and you will see a little bar at the top of the window with a back and forward button...


    Also if you find that it is necessary for you, it might make sense to have two copies of the same thing (one with page tags, one with window tags) and you can simply switch the StartupUri...

    <!-- app.xaml -->

    <Application ...
    StartupUri="WebPageCopy.xaml">

    ...

    </Application>

    to

    <!-- app.xaml -->

    <Application ...
    StartupUri="WindowsCopy.xaml">

    ...

    </Application>

    This is great though!!!

Comments for Windows Presentation Foundation: From a XBAP to an EXE