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

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

问题描述

我有 ViewModel1 和 View1 与之关联.我使用 IWindowManager 对象从 ViewModel2 (另一个视图模型)启动对话框窗口.ViewModel2 类的代码:

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();

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

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