4

in caliburn when i work with binding convention, and name a content control "CurrentPresenter" the framework automagically bind to the vm and locate the relevant view.

if i do this binding manually the view is not located.. how might i achieve this ability without the binding convention (my view is a user control)

Chen Kinnrot
  • 20,609
  • 17
  • 79
  • 141

1 Answers1

10

You should bind to View.Model attached property, which:

  • figures out the correct view to represent the VM
  • binds the view DataContext to the VM
  • pushes the view in the ContentControl's Content property

Example:

<!-- Caliburn v1.x -->
<ContentControl cal:View.Model="{Binding CurrentPresenter}" />

The previous snippet works in Caliburn v1.x, while in Caliburn v2 and Caliburn.Micro IPresesenterManager was renamed into IConductor (with some changes to interface members, too), so the binding should be:

<!-- Caliburn v2 & Caliburn.Micro -->
<ContentControl cal:View.Model="{Binding ActiveItem}" />
Marco Amendola
  • 1,468
  • 11
  • 11
  • 1
    10x, but is there a way to bind a user control to a view model? if i write in xaml some custom control tag how might i bind it to a view model? – Chen Kinnrot Aug 31 '10 at 06:53
  • The syntax is the same: . View.Model attached property can push the child VM's associated view into any "container" in the hosting view. The only requisite for the container is having a property named "Content" or another equivalent marked with ContentPropertyAttribute – Marco Amendola Aug 31 '10 at 11:34
  • Cheers for this, it really helped! – BenjaminPaul Apr 01 '14 at 08:36