包含两个Caliburn.Micro观点对话框有何看法? [英] Dialog view containing two Caliburn.Micro views?

查看:275
本文介绍了包含两个Caliburn.Micro观点对话框有何看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我使用Caliburn.Micro一个Windows WPF应用程序。主窗口视图/视图模型是由Caliburn.Micro处理。一位IT的按钮弹出它采用了不同的视图查看模型一个新的对话窗口。

I have a Windows WPF app in which I'm using Caliburn.Micro. The main window view/viewmodel is handled by Caliburn.Micro. One of it's buttons pops up a new dialog window which uses a different view-viewmodel.

在此对话框中我有一个容器(列表框和一些过滤器控件),我想制作成一个可重用的控制,这样我可以包括在其他的对话框。要做到这一点,我从对话框的视图中提取视图模型相关的代码并创建了一个新的视图和视图模型。这一切都看起来不错。

In this dialog I have a container (list box and some filter controls) that I want to make into a reusable control so that I can include it in other dialogs. To do this I extracted from the dialog's view and viewmodel the relevant code and created a new view and viewmodel. This all looks good.

的问题是,现在又回到对话中我有一个很大的空白,我需要可重复使用的控制去一个DockPanel中。

The problem is that now back in the dialog I have a dockpanel with a big empty space where I need the reusable control to go.

从对话框视图模型OnInitalize()我可以创建可重用的控制视图模型,但我不知道如何得到它的观点进入对话视图的DockPanel中。

From the dialog viewmodel OnInitalize() I could create the reusable control viewmodel, but I don't know how to get it's view into the dialog view's dockpanel.

要创建从主窗口视图模型的对话框我用的窗口管理器()。ShowDialog的(),以显示该对话框中的视图模型和Caliburn.Micro需要建立视图的照顾。有没有一种方法,我可以在对话框中的XAML指定我要嵌入视图的可重复使用的控制,并有卡利创建相应的视图/视图模型?

To create the dialog from the main window viewmodel I use WindowManager().ShowDialog() to display the viewmodel for the dialog and Caliburn.Micro takes care of setting up the view. Is there a way I can specify in the dialog's XAML that I want to embed the view for the reusable control and have Caliburn create the appropriate view/viewmodel?

还是我绕了错误的方式?

Or am I going about it the wrong way?

推荐答案

如果你有你的对话视图模型属性这是另一种视图模型类型,你ContentControl中添加到命名与此相同的属性,那么Caliburn.Micro将自动注入相当于你的财产视图模型类型到ContentControl中占位的观点你的对话视图,并绑定该视图模型类型的视图也自动。你是这个意思吗?是这样的:

If you have a property on your dialog view model which is another view model type, and you add a ContentControl to your dialog view which is named the same as this property, then Caliburn.Micro will automatically inject the view which corresponds to your property view model type into the ContentControl placeholder, and bind that view model type to the view automatically too. Is this what you mean? Something like:

// Dialog View Model
private MyReusableControlViewModel myReuseableControl;
public MyReusableControlViewModel MyReuseableControl
{ 
   get { return this.myReuseableControl; }
   set { this.myReuseableControl = value;  NotifyOfPropertyChanged(...); }
}

// Dialog View Model Constructor
public DialogViewModel()
{
  this.MyReuseableControl = new MyReusableControlViewModel();
}

// Dialog View
<DockPanel>
  ...
  <ContentControl x:Name="MyReusableControl" />
</DockPanel>



当然,理想情况下,你将要注入的对话视图模型的任何依赖关系(在这种情况下MyReusableControlViewModel ),反对抽象的工作对话视图模型里面,而不是具体类型。

Of course, ideally you would want to inject any dependencies of the dialog view model (in this case MyReusableControlViewModel) and work against abstractions inside the dialog view model, rather than concrete types.

这篇关于包含两个Caliburn.Micro观点对话框有何看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆