卡利微型取消从视图模型窗口关闭 [英] Caliburn Micro cancel window close from ViewModel

查看:101
本文介绍了卡利微型取消从视图模型窗口关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户点击一个窗口的关闭按钮,是否有可能取消从视图模型收盘还是我不得不求助于后面的代码?

When the user clicks the close button of a Window, is it possible to cancel the close from the ViewModel or do I have to resort to code behind?

从我可以告诉你,CanClose或TryClose不会做的伎俩。

From what I can tell, CanClose or TryClose doesn't do the trick.

推荐答案

您可能已经尝试过这一点,但我已经刚刚创建了一个快速测试,从屏幕和压倒一切的CanClose得出一个视图模型。

You may have already tried this but I've just created a quick test, deriving a view model from Screen and overriding CanClose.

public class ShellViewModel : Screen
{
    public override void CanClose(Action<bool> callback)
    {
        //if(some logic...)
        callback(false); // will cancel close
    }
}

这篇关于卡利微型取消从视图模型窗口关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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