Nested regions and data binding

Topics: Prism v2 - Silverlight 3
Sep 24, 2009 at 8:27 PM

I'm working on an app that is to display a complex object. Because the object is so complex I've seperated the details over several tabs and some tabs contain accordions and grids to further display the object. There's quite some logic involved so I'd like to seperate this into several modules (user controls) to make it maintainable. I'm currently struggling with the way to provide the data to each module / user control that it needs to show.

Let's assume my object looks like this:

  - Customer details
  - Orders
     - Order 1
        - Products
           - Product A
           - Product B
     - Order 2
        - Product A
        - Product B

I want to show the customer details on one tab using one module or user control and show the list of orders on a different tab using another module or user control. Let's say I have a page with a view model that exposes the Customer object. On the page I have a tab control with two tabs. How do I bind the Customer details and Orders each to a seperate module on a tab? How do I get the Customer details in the view model so that I can expose additional properties to the view based on data in the object?

I currently tried the view first approach in which I have a property CustomerDetails on my user control that I host on one of the tabs. The view hosts the view model inside its Resources collection. The page binds the Customer details of the Customer object to the CustomerDetails property of the control. This gives me access to the CustomerDetails in the view, but I need it in the view model too. I tried binding the CustomerDetails property to a property on the view model, but this a) does not work if I do it in XAML because you can't bind a property to an object in the resources collection and b) does not work from code since the binding doesn't fire.

I'm sorry if my question is a little vague, but my head won't stop spinning once I started working with Prism.

Sep 25, 2009 at 11:05 PM
Edited Sep 25, 2009 at 11:06 PM


Remember that you display views in regions (not modules), while a module can have none, one or multiple views. This thread explain this in more detail:

On to your particular situation, first I would define the Views I want to show. As far as I understand, in your scenario they would be:

  • CustomerDetailsView (with a CustomerDetailsViewModel)
  • Order (with order ViewModel, and just make product a list/datagrid with products for the order).

To use the View First approach (meaning that you build and “talk” to the view), you can use code like this:

public class CustomerView
    public CustomerView(CustomerDetailsViewModel model,…)
           this.DataContext = model;
           //more code here…

This way, you can simply bind to your ViewModel in your Views XAML. You can read more about Prism and MVVM in the following:

You might probably find the Prism-v2 RI application useful, as it has different views, and shows different ways of binding Views-ViewModels and displaying the views.

Please let me know if this helps.

Damian Schenkelman