Question

Floating document window focus

Posted 3 years ago by Avatar Matthew Rombola

I am in the process of moving our application to the new docking interface, and need a little assistance related to floating window focus.

Our application has many menu commands that operate on the document window specified in the DockSite.PrimaryDocument property. Let's say I have two document window tabs in the main window, and I float one of them to create a new window with a new tab group. I then select the document in the new floating window in order to run a menu command against it (Copy/Paste, for example). The PrimaryDocument property changes to the document in the floating window. When I go to the menu to select a command, the document in the main window regains focus and the PrimaryDocument property changes back to that window. So when I execute the command, it gets executed against the wrong document.

Visual Studio's behavior for document tabs in floating windows seems to be a little different. If I float a document to a new window, then go to the menu or toolbars to select a command, the document in the floating window remains focused so that the command executes against that document. This is how I would expect our floating windows to work as well.

I tried various methods to intercept different focus events and handle them, but the PrimaryDocument property changes before the focus events even fire.

Do you have any suggestions for how I would be able to get the desired focus behavior?


Comments (4)

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

Hi Matthew,

This problem is due to how WPF manages focus.  By clicking on the menu/toolbar on your main Window, you activate that Window, and WPF automatically restores focus to the last control on that Window that had focus, which could be another control in a document window there.  Since DockSite watches for focus moving into document windows to know when those document windows become "active" (and thus a primary document), the problem scenario occurs.

The only way to work around it (and is what VS does) is to prevent the main Window from activating when clicking on a menu/toolbar.  This thread on Stack Overflow talks about some ways to do that by using features added in .NET 4.0:

http://stackoverflow.com/questions/6410146/dockable-windows-floating-window-and-mainwindow-menu-integration


Actipro Software Support
Posted 3 years ago by Matthew Rombola

OK, I think that got me going in the right direction.

Thanks.

Posted 8 months ago by Matthew Bristow

I think I may have a similar issue but not 100%, my first scenario is related to the above but scenario two I would have expected it not to be active if that was the case?

Scenario One

I have two DocumentWindows docked.
The first I have three ToolWindows. Two of them are docked and one is floating. I select the floating ToolWindow and IsActive.
I switch to the second Document Window, and back to the first.
The IsActive ToolWindow is now one of the docked ToolWindows.

Scenario Two

However if I have a single ToolWindow which is floating when I switch back it then IsActive.

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

Hello Matthew,

If you are having trouble, kindly make a new simple sample project that shows it and send that to our support address with repro steps so that we can debug with it and see what's going on.  Make sure you remove any bin/obj folders from the ZIP you send and rename the .zip file extension to prevent spam blocking.  Thanks!


Actipro Software Support
Information The latest build of this product (2018.1 build 0672) was released 2 months ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.