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

发布于 2024-12-01 12:18:28 字数 278 浏览 4 评论 0原文

我将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十二 2024-12-08 12:18:28

是的,这是可能的。

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

这样,您甚至可以将多个视图绑定到一个视图模型。

示例:

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

您可以在此处查看工作示例< /a> (来自 CoProject 示例应用程序,第 9 部分)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文