如何从视图模型(Caliburn+WPF)关闭对话框窗口? [英] How to close dialog window from viewmodel (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屋!