取决于ContentControl(Caliburn.Micro)的不同视图

编程入门 行业动态 更新时间:2024-10-28 12:25:32
本文介绍了取决于ContentControl(Caliburn.Micro)的不同视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将ViewModels绑定到ContentControls,让Caliburn负责创建和绑定视图。但是,我想根据我要绑定到的ContentControl来自定义Caliburns ViewModel-> View约定。

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.

例如,一个常规的ContentControl,我想要一个常规的View绑定(SomethingViewModel-> SomethingView)。但是对于某些ContentControl,我希望Caliburn获取一个名为SomethingViewSpecial的视图。

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?

推荐答案

是的,有可能。

使用 cal:View.Context 附加属性,然后为指定的上下文命名视图,例如 YourNamespace.Something.ContextView (从视图模型名称中删除 ViewModel,添加一个点,以及Context属性的值)。

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.

示例:

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

您可以看到工作示例此处(摘自 CoProject 示例应用程序,第9部分)。

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

更多推荐

取决于ContentControl(Caliburn.Micro)的不同视图

本文发布于:2023-11-12 19:33:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582332.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   ContentControl   Caliburn   Micro

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!