private async void OnDataWindowClosing(object sender, CancelEventArgs args)
{
if (!_forceClose && !ClosedByButton)
{
var vm = ViewModel;
if (vm != null && vm.IsClosed)
{
// Being closed from the vm
return;
}
// CTL-735 always cancel, we will close later once we handled our async result
args.Cancel = true;
if (await DiscardChangesAsync())
{
// Now we can close for sure
_forceClose = true;
// Dispatcher to make sure we are not inside the same loop
#pragma warning disable 4014
Dispatcher.BeginInvoke(() => SetDialogResultAndMakeSureWindowGetsClosed(false));
#pragma warning restore 4014
}
}
}