Daily Archive for June 4th, 2006

Tips & Tricks for Flexible Application

In my previous post, I introduced my FlexibleApplication template. In this posts, I offer a couple tips & tricks.

Determing the App Model at Compile Time or Runtime

Depending on your application, you may want to do different things in the standalone and XBAP version. The Flexible Application template adds some goo (i.e. compilation constants & static helpers) to make doing this easier for you.

Conditional compilation:


	#if XBAP
	    //  XBAP specific code
	#else
	    //  Standalone specific code
	#endif

Runtime switching:


	if (MyApp.IsXBAP)
	{
	    //  XBAP specific code
	}
	else
	{
	    //  Standalone specific code
	}

XAML switching:


	<Grid>
	    <Grid.Resources>
	        <BooleanToVisibilityConverter x:Key="BoolToVis" />
	    </Grid.Resources>
	    <Button 
	        Visibility="{Binding Source={x:Static Application.Current}, 
	            Path=IsXBAP, Converter={StaticResource BoolToVis}}">
	                FOO BAR
	    </Button>
	</Grid>

Hiding Navigation Chrome

If you’re building a single page application, it doesn’t make sense to always show the navigation chrome on your standalone window.

Navigation Chrome

To remove this chrome, set the ShowNavigationUI property on Page


	<Page x:Class="SinglePageApp.Page1"
	    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	    Title="Page1"
	    WindowTitle="SinglePageApp"
	    ShowsNavigationUI="False"
	    >

VS Template: Flexible Application

In WPF, we support two main app models: standalone and XBAP.

Standalone apps are akin to traditional Windows apps. They run in their own window. They tend to be fully trusted (unrestricted access to the computer and its resources). And they are installed (either via an MSI, ClickOnce, or EXE distribution).

XBAPs, on the other hand, are browser hosted applications. They’re cached (using ClickOnce) and sandboxed. Users navigate to them (promptlessly) in the browser like they do any other website. (XBAP whitepaper & sandbox whitepaper)

What’s great then is, if you’ve written your app in a security & navigation friendly way, converting between standalone & XBAP is as easy as flipping a few project settings.

Flexible Application VS Template

In order to facilitate switching between app models, I’ve written a “Flexible Applcation” VS template. It enables you to maintain a single application project file and easily compile as standalone or xbap based on application configuration.

FlexibleApplication Flow Chart

How do I use it?

When creating a project, select “Flexible Application (WPF).” (Template installation structions below.)

When building/running the app, choose the configuration that you want:

Debug and Release will build a standalone app. XBAP Debug and XBAP Release will produce an XBAP

Sample

I updated the below SDK sample to work with the Flexible Application template. You can get the Beta2 code here and the June CTP code here.  Or straight to the xbap on Beta2 or xbap on June CTP.  

 

How do I install FlexibleApplication template?

  1. Copy this zip file to “%userprofile%My DocumentsVisual Studio 2005TemplatesProjectTemplatesVisual C#”. Don’t unzip the file – just copy the zip file as is.

Release notes

This version of the template does not support publishing.  For more information, see the template readme.

Some thank yous

- WPF SDK for a great cube app. (WPF SDK team’s blog)

- Ashish Shetty & Dennis Cheng for their VS template help.

- Beatriz Costa for her help setting up the XAML databinding

blog work blog

About 6 months ago, I took the plunge and started a personal blog. Recently, I thought it would be fun to post about what I do during the day (and sometimes night!): Windows Presentation Foundation (WPF).

On WPF, I am the security and partial trust sandbox program manager. I am also heavily invested in XAML Browser Applications (XBAPs). On this blog, you’ll find a lot of postings on these areas, as well as general WPF & industry musings.

The links:
Work blog: http://scorbs.com/work (rss)
Life blog: http://scorbs.com/life (rss)
Everything blog: http://scorbs.com (rss)