Float/Dock Events when using context menu

Docking/MDI for WPF Forum

Posted 7 years ago by Jeffrey Wong
Version: 16.1.0635

I ran into a situation where I was trying to detect when a tool window is docked/floating when using the context menu of the tool window to "Float" or "Dock", but I couldn't find an event handler (e.g,WindowsStateChanged etc.) that would work.

I think it's something similar to Docking/MDI - Demos > Simple IDE (in-line).  In the demo project, I'm right clicking on the About.txt tab (or solution explorer, document properties etc) and clicking float, but in the output window I didn't see any specific events being fired. 

I'm using the right event or is there maybe something else going on?

Comments (3)

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

Hi Jeffrey,

WindowStateChanged only fires when the docking window's State property changes, which is a switch between Docked, Document, and AutoHide.  A floated tool window is still considered Docked, but in a floating DockHost.  We have to think of things this way to support floating DockHosts that can contain MDI areas themselves with tool windows docked around the MDI.

We are open to enhancing things to suit your needs.  Can you describe more about your scenario, like what you need to know this for and are you wanting to know any time any docking window moves or changes anywhere?  Thanks!

Actipro Software Support

Posted 7 years ago by Jeffrey Wong

I think I've come up with a simple sample snippet that can be done in a simple WPF project:

Let's say I have the following setup:

      <docking:DockSite x:Name="MainDockSite">
                  <docking:ToolWindow Title="My Tool Window" x:Name="MyToolWindow"/>

 And in my code behind, I'm just logged a few statements to see what events are fired:

MainDockSite.WindowActivated += (sender, args) => Trace.WriteLine("WindowActivated: " + args.Window.Name);
MainDockSite.WindowsStateChanged += (sender, args) => Trace.WriteLine("WindowsStateChanged: " + String.Join(",", args.Windows.Select(w => w.Name)));
MainDockSite.WindowRegistered += (sender, args) => Trace.WriteLine("WindowRegistered: " + args.Window.Name);
MainDockSite.WindowUnregistered += (sender, args) => Trace.WriteLine("WindowUnregistered: " + args.Window.Name);
MainDockSite.WindowsOpened += (sender, args) => Trace.WriteLine("WindowsOpened: " + String.Join(",", args.Windows.Select(w => w.Name)));
MainDockSite.WindowsOpening += (sender, args) => Trace.WriteLine("WindowsOpening: " + String.Join(",", args.Windows.Select(w => w.Name)));
MainDockSite.WindowsDragged += (sender, args) => Trace.WriteLine("WindowsDragged: " + String.Join(",", args.Windows.Select(w => w.Name)));
MainDockSite.WindowsDragging += (sender, args) => Trace.WriteLine("WindowsDragging: " + String.Join(",", args.Windows.Select(w => w.Name)));
MainDockSite.WindowsClosed += (sender, args) => Trace.WriteLine("WindowsClosed: " + String.Join(",", args.Windows.Select(w => w.Name)));
MainDockSite.WindowsClosing += (sender, args) => Trace.WriteLine("WindowsClosing: " + String.Join(",", args.Windows.Select(w => w.Name)));
MainDockSite.FloatingWindowOpening += (sender, args) => Trace.WriteLine("FloatingWindowOpening: " + args.DockHost);

 When I run this, I:

  1. Float the tool window via it's context menu (FloatingWindowOpening and WindowStateChanged event fires)
  2. Dock the tool window via it's context menu (no event gets fired)

So I think my question is two-fold based on those two steps:

  1. How do I get a handle to the window that was floated from the FloatingWindowOpening event?
  2. How do I detect when the floating window is docked?
Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Jeffrey,

The FloatingWindowOpening event just fires so that you can initialize the floating window and perhaps change its default width.  It isn't really intended to be notifying of when a docking window itself is being floated, but you might be able to use it for that purpose by walking down the DockHost tree that is passed in.  Still, that's not what this event is really for.

When you re-dock a floated docking window from its context menu, the state isn't changing.  It's still considered as Docked state in both since it is docked in a floating DockHost and then later docked in the primary DockHost.

What I was asking in my previous reply was for you to tell me more about why you need to know when this scenario occurs.  We want to understand better about your needs so that we can come up with a solution to help.

Also we would need to know, are you looking to find some event for whenever a docking window gets moved from one place to another? 

Do you only care if it moves to a new dock host (like floating vs. primary), or do you also want to know if it moves to another docked location in the same dock host?

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.