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.
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.