简体   繁体   English

在 caliburn micro 中绑定视图和模型

[英]Bind view and model in caliburn micro

How to make caliburn.micro bind child view models to child visuals?如何使 caliburn.micro 将子视图模型绑定到子视觉对象?

I have an ObservableCollection of items in a VM.我在 VM 中有一个ObservableCollection项目。 Items are created manually, caliburn micro is not used.项目是手动创建的,不使用 caliburn micro。 Sometimes they are deserialized from disk.有时它们会从磁盘反序列化。

Views are created by WPF framework through data binding and data templates, I don't need to search anything, and I don't want to use ContentControl, I want to instantiate the correct visual tree in XAML, from my data templates there.视图是由 WPF 框架通过数据绑定和数据模板创建的,我不需要搜索任何内容,也不想使用 ContentControl,我想在 XAML 中从我的数据模板中实例化正确的可视化树。

Is there a way to force caliburn micro to bind them together without creating neither views nor VMs with it?有没有办法强制 caliburn micro 将它们绑定在一起而不用它创建视图和 VM?

Specifically, I want conventions applied automatically, so <Button x:Name="act" /> from the data template calls public void act() on it's data context when clicked.具体来说,我希望自动应用约定,因此数据模板中的<Button x:Name="act" />在单击时对其数据上下文调用public void act() Like it happens when caliburn micro creates either view or VM using these locators.就像 caliburn micro 使用这些定位器创建视图或 VM 时发生的那样。 The data context is set by WPF when it created an item visual from data item.数据上下文由 WPF 在从数据项创建项目视觉对象时设置。

您可以将DataTemplate根元素的cal:Bind.Model附加属性绑定到DataContext如下所示:

<Grid cal:Bind.Model="{Binding}"> ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM