Caliburn Micro:“儿童”主 shell VM 中的 VM
我从 Caliburn.micro 开始,有点困惑。假设我有一个带有 2 个窗格的 UI,例如(这是一个假样本)CustomersView 和 CustomerView,以及 2 个相应的 VM、CustomersViewModel 和 CustomerViewModel。
现在,假设我想将两个窗格都包含到主 shell 中,该主 shell 应该能够访问所有 VM 之类的数据成员:例如,
public class MainViewModel
{
private CustomerViewModel _vmCustomer;
private CustomersViewModel _vmCustomers;
...
}
由于视图模型是由 CM 创建的,我如何将主 shell 连接到它们的每个实例?或者这是一个错误的做法?我在这里不需要规范意义上的导体,因为我没有像在 MDI 中那样激活或停用一组窗格:我有一个带有一些窗格的 SDI UI,每个窗格都由其虚拟机支持,还有一个主 shell,它应该操纵他们所有人。在类似情况下正确的做法是什么?
I'm beginning with Caliburn.micro and I'm a bit confused. Say I have a UI with 2 panes, e.g. (this is a fake sample) CustomersView and CustomerView, and 2 corresponding VM's, CustomersViewModel and CustomerViewModel.
Now, say I want to include both panes into a main shell, which should be able to access all the VM's like data members: e.g.
public class MainViewModel
{
private CustomerViewModel _vmCustomer;
private CustomersViewModel _vmCustomers;
...
}
As viewmodels are created by CM, how can I connect my main shell to each instance of them? Or is this a wrong approach? I do not need a conductor in its canonical sense here, as I'm not activating or deactivating a set of panes like in a MDI: I have a SDI UI with some panes, each backed by its VM, and a main shell which should manipulate all them. What is the right approach in a similar scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 MainView.xaml 中添加两个 ContentControl,并为它们指定与代表 ViewModel 的两个属性的名称相匹配的名称。
视图模型:
视图:
In your MainView.xaml add two ContentControls and give them names that match the names of two properties representing your ViewModels.
ViewModel:
View:
另一种方法是
,
这可以让读者更好地了解从视图中期望得到什么。混合性也可能会更好。
Another way to do it is
and
This gives a reader a better idea what to expect from the view. Blendability could be better, too.