Nested Views & Blend

Jul 10, 2010 at 8:16 PM

Hi, I'm new to Caliburn Micro, and I have a simple situation which I got working, but I'm not sure if it's "best practice" due to the lack of documenation and samples at this point.

Here is the xaml for my ShellView, and the ShellViewModel is a Screen:

        <models:MainViewModel x:Key="MainViewModel" />
        <views:MainView x:Name="Views_MainView"  caliburnmicro:View.Model="{StaticResource MainViewModel}" />

The MainView is a usercontrol with a MainViewModel which is also a Screen.

1. The code above works, but is this best practice? Am I supposed to use the AttachedProperty View.Model to do the hook-up when nesting views?

2. In the design view of Blend\VS I get "MainView not found". So, this technique is not designer friendly, which makes me think it's the wrong implementation. If I follow the Blend MVVM sample, I would use DataContext="{StaticResource MainViewModel}" and use binding syntax in xaml.



Jul 11, 2010 at 12:36 AM
I tend to shy away from instantiating VMs in resources because I like to have an IoC container build those. However, this approach works fine for a number of scenarios, particularly where the composition of the UI isn't that dynamic and the VM don't have many dependencies. To fix your issue, use the Bind.Model attached property instead of View.Model.
Jul 11, 2010 at 4:30 AM

I agree. Do you have a simple sample where you inject screens dynamically in and out using Caliburn Micro? Is it going to require MEF to be implemented in the IOC?

Interestingly, I can do dynamic swapping out of the Silverlight box by:

  1. creating a ContentControl
  2. Binding the ContentTemplate property to a VM DataTemplate property
  3. load another DataTemplate via Resources 
  4. update the VM DataTemplate property
  5. The default template can be changed for Blend-ability.

I'm curious to see the Blend workflow in this area with Caliburn Micro...maybe I will figure it dynamic screens, but a sample\snippet in this area might be helpful to others.

thanks, RHogue