不同的视图取决于 ContentControl (Caliburn.Micro)
我将 ViewModel 绑定到 ContentControls 并让 Caliburn 负责创建和绑定视图。但是,我想根据我绑定到的 ContentControl 自定义 Caliburns ViewModel->View 约定。
例如,常规的ContentControl,我想要绑定常规的View(SomethingViewModel -> SomethingView)。但对于某个 ContentControl,我希望 Caliburn 获取名为 SomethingViewSpecial 的视图。这可能吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的。
使用
cal:View.Context
附加属性,然后为指定上下文命名您的视图,例如YourNamespace.Something.ContextView
(从视图模型名称中删除“ViewModel”,添加点,以及 Context 属性的值)。这样,您甚至可以将多个视图绑定到一个视图模型。
示例:
您可以在此处查看工作示例< /a> (来自 CoProject 示例应用程序,第 9 部分)。
Yes, it is possible.
Use
cal:View.Context
attached property and then name your view for the specified context likeYourNamespace.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:
You can see working example here (from CoProject sample application, part 9).