"Closing" event not firing on Floating toolwindow

Docking/MDI for WPF Forum

Posted 13 years ago by Bret Naughton
Version: 10.2.0533
I have code that I am executing on the "closing" event of a toolwindow. What I have noticed is that the code is not being executed if I close the toolwindow when it is floating/undocked.

Is there another method or event I have to check for in order to trigger my code.


Comments (5)

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

I'm assuming you mean the DockSite.WindowClosing event. I tried this in our Sample Browser and the event appears to be firing fine for floating ToolWindows.

For questions like this, please try to either put together a small sample project that reproduces the issue and email it over to our support address, or give detailed steps on how to reproduce with our Sample Browser. Once we have that we can take a closer look.

Actipro Software Support

Posted 13 years ago by Bret Naughton
Thanks for that. unfortunately the way I am doing things at the moment I use the AddPreviewExecutedHandler event. The reason is that I have to calculate - based on the toolwindow selected - other toolwindows and actions to close down. Therefore I set my required logic at this preview stage (may even include prompting the user and not closing anything) and then close as many of the toolwindows required. (If I use the Window Closing event, I get into all sorts of looping/logic issues)

CommandManager.AddPreviewExecutedHandler(Window, AddressOf OnPreviewEvent)

Private Sub OnPreviewEvent(ByVal sender As Object, ByVal e As ExecutedRoutedEventArgs)
If e.Command Is DockingCommands.CloseWindow Then
e.Handled = True
End If
End Sub

What I am finding is that the preview event is not fire at all when closing from wither a floating window or a auto-hide window.

Appreciate any advice on how I can include the float/auto-hide windows into my preview logic.

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

The CommandManager.AddPreviewExecutedHandler must be added to every instance of Window, since it takes a specific element to which the handler should be attached. The floating windows use separate Windows by default, except when run via XBAP. You can create a custom class that derives from DockSite and override the CreateRaftingWindow method. This will return an instance of IRaftingWindow, which you can try to cast to Window and attach your handler there.

For auto-hide windows, if you have UseHostedAutoHidePopups set to false then it will use a separate Popup to ensure it's content appears on top of any interop content. Otherwise, your handler should be called normally. Are you setting UseHostedAutoHidePopups to false?

Actipro Software Support

Posted 13 years ago by Bret Naughton
Thanks for your assistance on this.

Unfortunately still unable to get this working for both the auto-hide & floated windows.

For the auto-hide windows, I defined my main docksite as follows.

Dim dockSite As New TheDockSite
DockSite.Name = "dockSite"
DockSite.UseHostedAutoHidePopups = False
DockSite.ToolWindowsTabPlacement = TabPlacement.Top
DockSite.ClosePerContainer = True
DockSite.CanToolWindowsRaft = True
DockSite.CanToolWindowsAutoHide = True
DockSite.ToolWindowsSingleTabLayoutBehavior = SingleTabLayoutBehavior.Hide
DockSite.ToolWindowsHaveTitleBars = True
DockSite.ToolWindowsHaveOptions = True

Then within the Public Sub New() I set me preview executed handler as described in the previous post.

' Register preview event handler, to check for closing of windows
CommandManager.AddPreviewExecutedHandler(Window, AddressOf OnPreviewEvent)

However, when I auto-hide and close when in the auto-hide state, the AddPreviewEvent is still not triggered (assuming from your email that there is nothing else I need to do as long as the UseHostedAutoHidePopups is false.

Also, as far as triggering the Preview event for the floating windows, I am confused as to how I should be casting the rafting window. I am presuming I need to cast this as a window so that CommandManager.AddPreviewExecutedHandler that I described above is triggered for this window - but I am not having any luck in converting this to a window. Is there anything obvious I am not doing here.

Public Class TheDockSite
Inherits DockSite

Protected Overrides Function CreateRaftingWindow(ByVal raftingHost As RaftingHost) As IRaftingWindow
Dim RaftingWindow = MyBase.CreateRaftingWindow(RaftingHost)

'Dim Window As Window = CType(Result, Window) - this is throwing error

Return RaftingWindow
End Function
End Class

Thanks again for your help.
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Bret,

Adding handler to your main window instance will only handle events raised by it's visual children. If any other windows are created, such as floating window, their events will not bubble up through your main window.

If you have UseHostedRaftingWindows set to false, then CreateRaftingWindow will return an instance of RaftingWindow (which is a Window). If you have UseHostedRaftingWindows set to true, then it will return an instance of RaftingWindowControl. If you are running in an XBAP application, then the UseHostedRaftingWindows is meaningless and forced to be true (as Windows are not supported in partial trust applications).

Either way, I'm not sure why your code is throwing an exception. It looks like you pass "Result" into CType, when that should be "RaftingWindow". But we'd need complete sample to be sure.

The auto-hide popups are a similar story. If UseHostedAutoHidePopups is false, then the auto-hidden ToolWindows are shown in a Popup instead of the adorner layer. There's no easy way to hook into the Popup though, but we made a change so the Popup is a logical child of the DockSite to allow it's events to bubble up through the DockSite to the main window. This will be included in the next maintenance release.

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.