Saturday, November 29, 2008

patterns & practices: Composite WPF and Silverlight Drop 6

It's been couple of days since I started playing with Prism V2 Drop 6 (You can download it from here). Of course I've been using CompositeWPF aka Prism V1 for a longer time, and I must admin it's an excellent framework, but I wanted to see it's new Silverlight part. Here's what I've found so far.

In general, drop 6 seems working just fine. It contains the following features known from the WPF part:
  • modularity
  • event broker
  • regions
It goes without saying that everything is wired up with P&P Unity 1.2 that also has a port for Silverlight. So if all you need is a good DI container, you can simply grab only the Unity bits from that release.

As I previously said, everything is working fine. One thing disturbs me, however. On the very first version of Prism, I was able to use ordinary classes as views, the view was then defined as a data template. So I could have written something like that:

   48 var downloadItemPresenter = m_Container.Resolve<NavigationItemPresenter>();
   49 downloadItemPresenter.Text = "Download";
   51 m_RegionManager.Regions[RegionNames.NavigationPanel].Add(downloadItemPresenter);

In this example, NavigationItemPresenter represents my custom button. However, there is no explicitly given view - the view is defined via data template. Unfortunately, from unknown reasons, this doesn't work in Silverlight. I receive NullPointerException. After "investigation" it turned out that internally, the view is casted to... DependencyObject!!! Why is that?! I don't known. I even tried to extend the DependencyObject class (yes, it's possible despite the fact many people say it's not), but I got other exceptions. To sum up, I use this release in my small project (small page for the product I'm currently working on, I'll post about it as soon as it's finished), but it's a pity that the cool approach with views defined using data templates doesn't work so far. Highly recommended.

No comments: