How to get notified only when a ToolWindow is permanently destroyed?

Docking/MDI for WPF Forum

Posted 4 months ago by Michael Janulaitis - Corner Bowl Software
Version: 22.1.0
Avatar

I need to call my view model dispose methods when a view is perminenty destroyed but not when hidden.  This typically works just fine using DockSite.WindowsClosed event handlers.  On Server 2016 when I close my RDP session ToolWindow.WindowsClosed is called but the window is not actually closed.  As soon as I log back into my RDP session I see the Windows all loaded and displayed.  The problem is that my dispose method was called causing all my data and subscriptiosn to get destroyed.

Comments (1)

Posted 4 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Michael,

The DockSite.WindowsClosed event fires when the docking windows are hidden and removed from the layout (such as when the user clicks the close button in a tool window's title bar), but not necessarily when they are permanently destroyed.  As such, I would not recommend calling your view-model's Dispose method from that event handler, because if the tool window is reopened, the same view-model would be used that is now disposed.

For your case, the DockSite.WindowUnregistered event is what is called after a tool window is closed AND it has been "destroyed", which means is being disassociated with the DockSite.  That is the place you'd want to call a view-model Dispose method.  You can read more about that in this documentation topic.

Note that tool windows do not destroy themselves when they are closed, but document windows DO destroy themselves on close by default.  This is due to document windows generally having a different lifecycle than tool windows.  That default can be changed if you wish, based on information in the same linked documentation topic.


Actipro Software Support

The latest build of this product (v22.1.2) was released 1 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.