When our users click the "X" on a Syncfusion DockingManager docked tab to close the window, I want to detect if the currently displayed document is dirty, and if so, ask the user if they want to save the document before closing. Standards dictate that the user should be able to cancel the closure at this point.
private void DockingManager_DockStateChanging(FrameworkElement sender, DockStateChangingEventArgs e) {
// This handles (and perhaps cancels) the window closure if there are unsaved changes to a
// drawing.
if (e.TargetState == DockState.Hidden) {
if (sender is DrawingWindow && (sender as DrawingWindow).IsDirty) {
bool cancelThis = ! (sender as DrawingWindow).ConfirmSaveBeforeClose();
e.Cancel = cancelThis;
}
}
}
private void DockingManager_DockStateChanged(FrameworkElement sender, DockStateEventArgs e) {
// This does the actual window closing.
}
The problem is that the window is closed BEFORE DockingManager_DockStateChanging is called. Therefore, e.Cancel, even if true, is too late, and the operation cannot be undone.
This seems like a bug to me. Alternately, if this is the designed behavior, how can I programmatically cancel a window closure? It appears that the Windows Forms DockingManager has a DockAllow event that might do this kind of thing; however this event does not exist in WPF.
Thanks.