how to cancel window activation?

Docking/MDI for WPF Forum

Posted 8 years ago by Gregory Whitcomb - President & CEO, LittleFlock Systems
Version: 10.2.0533
Avatar
I have an application where I want to prompt the user if he attempts to switch the active docking window (either DocumentWindow or ToolWindow) if he has changes from the previous window that haven't been saved. If the user specifies "Cancel", then I want to prevent a switch to the new window. To cancel and return to the previous window, I tried setting DockingWindowEventArgs.Cancel=true in both a WindowActivated as well as WindowDeactivated event handlers for the DockSite... no luck (it doesn't seem to have an effect). Also, I've tried to Activate the previous window within the WindowActivated/WindowDeactivated handlers, but also no luck. When I use SelectionChanged event handlers for the TabbedMdiContainer and ToolWindowContainer, I have limited success (basically, I'm setting SelectedItem within the handlers to the previous window when cancel is desired). The problem with this approach is that rafted windows (when the user moves a documentWindow or ToolWindow off the main window) apparently don't have these event handlers, so I can't check to see if the user's data was changed and then prompt for Cancel. Any ideas? Thanks!

Comments (1)

Posted 8 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Gregory,

We don't currently support cancelling a selection change. Things can get tricky in that area, since the selection can change for a number of reasons (user selects a tab, moves focus, opens/docks/autohides/floats/closes a window).

The rafting windows are separate Window instances, and therefore their events will not bubble up through the DockSite and the main Window. You would need to add a class handler for the RaftingWindow and the SelectedChangedEvent to be able to handle those. But the cleanest solution would be use to an attached behavior. Effectively, you create a custom class (i.e. MyCustomBehavior) with a single attached dependency property of type bool (i.e. IsManaged). You would add a property value changed handler for IsManaged, where you would attach to the SelectedChanged event of the ToolWindowContainer/TabbedMdiContainer when the value is changed to true and detach the handler when it's false.

Then you'd set MyCustomBehavior.IsManaged to true for all instances of ToolWindowContainer/TabbedMdiContainer using an implicit Style defined in your application resources. Because the Style is in your application resources, it will be picked up by both the main window and any rafting windows.


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.