Martijn's blog - E-Commerce, EAI, BizTalk and .NET


Supporting WPF XML Browser Applications (XBAP) in a CompositeUI Application Block application

Currently, we’re building a real application in WPF for a local government. The application uses the MVC pattern quite heavily, so I did a test to see whether we could use the Composite UI Application Block (CAB, read more about it’s architecture and use, download it from MSDN, play with the labs to understand it) to enable easier composability in order to distribute our use cases more easily throughout the development team, decouple logic from UI even more, etc.

It turns out the CAB currently doesn’t support WPF. After some searching, I discovered Kent Boogaart from Australia (thanks Dion!) is busy writing a support layer for WPF in CAB. So far, so good. Testing the download he provided, however, revealed the implementation doesn’t support so-called XBAP applications.

XBAP application are browser hosted WPF applications and are different in some aspects to ‘traditional’ WPF applications. For instance, the Application object which is the root for all WPF applications, doesn’t allow you to call the Run method if the WPF application is running within a browser. This is because of the asynchronous nature of the webbrowser.

After a few simple modifications to Kent’s code and a little more trickery, I had the BankTeller application working in XBAP. Well, sort of… The thing with CAB is that it assumes synchronous applications. An example of this (taken straight from Microsoft.Practices.CompositeUI.CabApplication):
public void Run()
 Builder builder = CreateBuilder();



 // Whoops for non-blocking Start()s
 if (visualizer != null)


As I explained earlier, XBAP applications take offense to calling the Run method on their Application, they’re asynchronous. In order to make XBAP applications work, a few modifications have to be made to CAB itself.
  1. Don’t call Run on the Application class.
  2. Ensure the correct UI element get’s displayed.
  3. Remove the dispose calling from the main Run() method of Microsoft.Practices.CompositeUI.CabApplication.
  4. Implement a correct IDisposable pattern for cleaning up resources once the Application is actually done with them.
  5. Ensure we call Dispose to clean up used resources.
For those just interested in the endresult, a modified WPF port capable of supporting CAB based applications in XBAP, you can download the example.

If you’re interested in more detail about the changes I made and how I did this, please read the whitepaper I wrote, which can be downloaded here.

A special thanks to Kent Boogaart for creating the WPF port for CAB, without which I wouldn’t have been able to put CAB to use in my WPF scenario!


Post a Comment

Links to this post:

Create a Link

<< Home