Caliburn Micro 取消窗口从 ViewModel 关闭

发布于 2024-12-25 21:01:59 字数 95 浏览 4 评论 0原文

当用户单击窗口的关闭按钮时,是否可以从 ViewModel 取消关闭,还是必须诉诸代码隐藏?

据我所知,CanClose 或 TryClose 并不能解决问题。

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯 2025-01-01 21:02:00

您可能已经尝试过此操作,但我刚刚创建了一个快速测试,从 Screen 派生视图模型并重写 CanClose。

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

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文