In the context of WPF excluding the root ViewModel, at what point does binding occur?

Topics: Conventions
Mar 31, 2012 at 7:57 PM


I've been stepping through the framework's code, trying to get a better understanding of how everything gets glued together. One part I can't find is, in the context of WPF, at what points are ViewModels bound to Views. I see the view locater but I can't seem to find how it is called and how the binding of Views to ViewModels gets activated.

I would be delighted if someone could create a small list of points that I could look at where this binding occurs.

Apr 1, 2012 at 2:23 AM
Edited Apr 1, 2012 at 2:23 AM

Three places:

1. The Bootstrapper

2. The WindowManager

3. The View.Model attached property (which is sometimes applied by convention).

The last point is probably the most important because it enables rich composition.

Apr 1, 2012 at 1:21 PM
Edited Apr 1, 2012 at 1:22 PM

I think the last point may be the one I need to research more, or may be the part I am missing. In the bootstrapper I can see the DisplayRootViewFor() which I presume is the Bootstrapper binding you were talking about. I'm assuming this is what enables you to bind a ShellViewModel to a ShellView when the app starts.

The WindowManager only seems to be called by the framework in the Bootstrapper or by the end user of the framework if needs be. That still doesn't explain how everything is composed together. That leaves the View Class which seems to be a collection of dependency properties that look like they are performing composition but I am not sure how they are called.

If I make a window with a place holder for switching out Views called ActiveItem, as I switch out the ViewModels, something is causing the VM's View to be found and bound. This is the part I cannot seem to find. What is happening in that instance, where the end user is not explicitly requesting the View?

Apr 2, 2012 at 2:58 AM

By convention, if we find a ContentControl with the same name as an object property, we set the View.Model attached property on it, which is what triggers composition.

Apr 2, 2012 at 8:05 AM

Ah! That makes sense, ok I need to go snoop around the ConventionManager and the View.cs Attached Properties. Cheers Rob!

Apr 2, 2012 at 8:06 AM

Have you read the documentation carefully?

Most of the architectural details are well explained in the articles provided in the Documentation section. :)

Apr 2, 2012 at 9:09 AM

You mean the soup to nuts?

Yes, I've read it. Most of the documention in that series is in the context of consuming Caliburn.Micro as an end user, currently I am deep diving through the framework to find out why's an really understand how everything is composed together. 

All my experience with Caliburn.Micro is in the context of WP7, which has the navigation service wrapper that handles binding so some of the WP7 stuff is completely new to me.

It might not be a bad idea once I am finished to maybe submit some additions to the documentation.