如何从viewmodel(Caliburn + WPF)关闭对话窗口? [英] How to close dialog window from viewmodel (Caliburn+WPF)?

查看:701
本文介绍了如何从viewmodel(Caliburn + WPF)关闭对话窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ViewModel1 和与其关联的View1。我使用 IWindowManager 对象从 ViewModel2 (另一个viewmodel)启动对话窗口。代码 ViewModel2 class:

I haveViewModel1 and View1 associated with it. I start dialog window from ViewModel2 (some another viewmodel) using IWindowManager object. The code from ViewModel2 class:

windowManager.ShowDialog(new ViewModel());

所以,我有对话窗口与View1用户控件。

So, I have Dialog Window with View1 user control.

我的答案是下一个 - 我可以使用红色关闭按钮关闭该对话框窗口,但如何使用我的具体按钮(包含在 View1 用户控件)中关闭它,包含关闭命令( Command = {Binding CancelCommand} )中的取消按钮,当然包含 CancelCommand ViewModel1 类。

My answer is next - I can close that dialog window using red close button, but how to close it using my specific button (contained in View1 user control), something like "Cancel" button with close command (Command={Binding CancelCommand}), CancelCommand of course is contained in ViewModel1 class.

推荐答案

如果您的视图模型扩展 Caliburn.Micro.Screen

It's even easier if your view model extends Caliburn.Micro.Screen:

TryClose();

这篇关于如何从viewmodel(Caliburn + WPF)关闭对话窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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