Convention: ContentControl.ContentProperty <- Conductor.ActiveItem

Topics: Conventions, UI Architecture
Sep 27, 2012 at 9:30 AM
Edited Sep 27, 2012 at 10:14 AM


there is a Convention for ContentControl that Rob Eisenberg describes like this:

"The convention for ContentControl is a bit interesting. If the item we are binding to is not a value type and not a string, then we assume that the Content is a ViewModel. So, instead of binding to the Content property as we would in the other cases, we actually set up a binding with CM’s custom attached property: View.Model. This property causes CM’s ViewLocator to look up the appropriate view for the view model and CM’s ViewModelBinder to bind the two together. Once that is complete, we pop the view into the ContentControl’s Content property. This single convention is what enables the powerful, yet simple ViewModel-First composition in the framework."

Simplified, it's a binding between a ContentControl and a ViewModel. I wonder if it is possible to define a convention that makes a binding between a ContentControl and a Conductor without the indirection of an additional View / ViewModel layer.

Like this: If ViewModel is a Conductor then bind ContentControl.Content to the View of (ViewModel as Conductor).ActiveItem else bind it to the View of ViewModel (existing convention).

If it's possible, how would it be done? I'd prefer a solution by convention and not something like

<ContentControl x:Name="CenterConductor" cal:View.Model="{Binding CenterConductor.ActiveItem}" />

if possible. Thanks a lot!