Different View depending on ContentControl (Caliburn.Micro)

狂风中的少年 提交于 2019-11-30 11:27:54

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/7190137/different-view-depending-on-contentcontrol-caliburn-micro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!