UWP / WinRT: Detect when a popup is about to be cl

2019-09-10 23:44发布

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

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.

1条回答
叛逆
2楼-- · 2019-09-11 00:16

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?
    }
});

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.

查看更多
登录 后发表回答