How detect that a ToolWindow closed by "x" button?

Docking/MDI for WPF Forum

Posted 13 years ago by Arthur
Version: 11.1.0542
In my scenario i am closing ToolWindow programmatically calling
Close() function in several situation related application UI requirement,
but also user can close by standard "x" button.
How can i distinguish these close events?

thanks in advance

Comments (3)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Arthur,

That is something that you'd currently have to track manually. You could create a custom ToolWindow class that has a flag property you can set, and then check for that in the WindowClosed event. So you'd set the flag to true before calling Close, then reset it to false in the WindowClosedd event.

Or you could just use the Tag property, but that is not as intuitive.

Actipro Software Support

Posted 5 years ago by Matthew Bristow

Sorry, to dig up an old post but figured it makes more sense than adding to the post rather than a duplicate but I imagine this is still the case?

My scenario is that when we close ToolWindows via the 'x' we hide it ie IsOpen = false, and in our DockSite (which inherits from DockSite) we override the OnWindowsClosed and notify our controller that the user has closed it.

I've been able to track this in my ViewModel, as every scenario will be UserClosed = true, but when I dispose of the ToolWindow ourselves we flip UserClosed to false so then the code within OnWindowsClosed isn't executed.

This works happy days, until someone uses ToolWindows.Clear(), but anyway.

With this scenario in mind, is there a way I can use ToolWindow as a base, and then use that type within the DockSite as my ToolWindow type?

Posted 5 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Matthew,

I believe your company uses MVVM patterns.  The DockSite.GetContainerForItemOverride method is what generates the ToolWindow "container" for a view-model.  It's default implementation is this:

protected virtual DockingWindow GetContainerForItemOverride(DockingWindowItemKind kind) {
	if (kind == DockingWindowItemKind.Document)
		return new DocumentWindow(true);
		return new ToolWindow(true);

You can override that method to provide your own inherited class instead if you like.  It works in the same way ItemsControl does and is described in the "MVVM Features" documentation topic.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.