UWP/WinRT:检测何时关闭弹出窗口 [英] UWP / WinRT: Detect when a popup is about to be closed

查看:122
本文介绍了UWP/WinRT:检测何时关闭弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测弹出窗口何时要关闭?

How can I detect when a popup is about to be closed?

与WPF中存在此类事件的WPF不同,UWP中Popup类没有Closing事件.

The Popup class does not have a Closing event in UWP, unlike in WPF where such an event exists.

我需要它来保持弹出窗口的状态,因为布局可以由用户修改.

I need this in order to persist the state of the Popup because the layout can be modified by the user.

推荐答案

您已经知道,没有关闭事件.通过注册IsOpen属性更改(如果IsLightDismissEnabled属性设置为true ...),您可能会很幸运

As you already know, there is no Closing event. You might get lucky by registering to IsOpen property change (if IsLightDismissEnabled property is set to true...)

this.popup.RegisterPropertyChangedCallback(Popup.IsOpenProperty, (d, e) =>
{
    if (!this.popup.IsOpen)
    {
        // do something, popup is closing?
    }
});

因为发生在LostFocus和Closed事件被触发之前.除此之外,如果不是为了避免依赖于关闭事件而变得很复杂的话,还可以重新设计持久数据的方式以始终保持它们.

because that happens before the LostFocus and Closed events get fired. Other than that, you can redesign the way you persist data to persist them all the time if it's not something very complex to avoid having to depend on the closing event.

这篇关于UWP/WinRT:检测何时关闭弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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