Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different View depending on ContentControl (Caliburn.Micro)

I'm binding ViewModels to ContentControls and letting Caliburn taking care of creating and binding the view. However, I would like to customize Caliburns ViewModel->View convention based on which ContentControl I'm binding to.

For example, a regular ContentControl, I want the regular View to bind (SomethingViewModel -> SomethingView). But for a certain ContentControl, I want Caliburn to fetch a View named for example SomethingViewSpecial. Is that possible?

like image 238
Kristoffer Lindvall Avatar asked Aug 25 '11 12:08

Kristoffer Lindvall


1 Answers

Yes, it is possible.

Use cal:View.Context attached property and then name your view for the specified context like YourNamespace.Something.ContextView (remove "ViewModel" from your view model name, add a dot, and the value of Context property).

By that, you can even bind several views to one view model.

Example:

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

You can see working example here (from CoProject sample application, part 9).

like image 152
gius Avatar answered Oct 02 '22 23:10

gius