Nested Views

Mar 19, 2012 at 10:43 AM

Hi Tony,

First of all I want to thank you for your simple mvvm toolkit. I worked for some time in using the mvp pattern. Now I need to start someting new in WPF and after some research I decided to use the MVVM pattern. Your toolkit really helped me to get on track really fast and easy.

Now my problem. I first created a simple poc without mvvm. My model is a tree like structure. It is a planning line with some text (main model) and with 5 days (day model) as children. Within every day there can be zero or more planned persons. Now I have created a usercontrol with dependency properties that represents a day and can bind to a day model.

I have a grid that is bound to the main model and I bind the text to the main model text properties. I have 5 usercontrols in there and I bind every controle to the xth instance of the day model in de main model like this


="{Binding Days[0].QuantityRequired}"

. The QuantityRequiredText is a dependency property the is associated to a textbox in my usercontrol. The Days is a List<> of day models in my main model which have a property quantityRequired. This works all very well.

Now I want to refactor this to mvvm using the toolkit. I have created two viewmodels and two views for the main and for the day. The main view I bind to the main view model, this works al fine. Now I have nested 5 day views in the grid of the main view, but how do I bind them to the 5 day entities that are in the main model? Can I directly bind to children in the main model or do I need to make a list of 5 day view models.

Could you please give us a simple example how to handle nested views with parent/child models?

Mar 25, 2012 at 8:15 PM

I am also interested in this. I am the developer of Catel, and it supports nested views (and nested view models), but I am always curious how this is solved in other frameworks.