Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

binding to my current presenter in caliburn without binding convention

Tags:

caliburn

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)

like image 397
Chen Kinnrot Avatar asked Dec 28 '22 08:12

Chen Kinnrot


1 Answers

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}" />
like image 172
Marco Amendola Avatar answered Feb 23 '23 00:02

Marco Amendola