Supporting WPF XML Browser Applications (XBAP) in a CompositeUI Application Block application
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.
- Don’t call Run on the Application class.
- Ensure the correct UI element get’s displayed.
- Remove the dispose calling from the main Run() method of Microsoft.Practices.CompositeUI.CabApplication.
- Implement a correct IDisposable pattern for cleaning up resources once the Application is actually done with them.
- Ensure we call Dispose to clean up used resources.
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!