Auto-hide tool window not hidden when clicking on another window

Docking/MDI for WPF Forum

Posted 3 years ago by Phil Devaney
Version: 16.1.0632
Platform: .NET 4.5
Environment: Windows 10 (64-bit)
Avatar

As I mentioned in a previous post, we are using auto-hide tool windows with no additional UI (tabs, title bar etc) to provide a "slide-in panel" feature. When the tool window's top-left corner is exactly at (0,0) screen coordinates (e.g. when parent window is in full screen mode) then clicking on another window (on another monitor) doesn't hide the tool window.

We have a Blueprint licence so I did some debugging. The problem seems to be with the use of Mouse.GetPosition in AutoHidePopupPanel.OnIsKeyboardFocusWithinChanged. There is a known issue with this method when the mouse is not within the calling window (see https://wpf.2000things.com/2012/10/18/671-mouse-getposition-only-works-when-mouse-is-in-window/) - in this case it always returns (0,0) relative to the passed element, which if the passed element is itself at (0,0) is always (0,0). The next line checks if the mouse is over the popup panel, which is always true so the hide is skipped.

I tried making a change to P/Invoke GetCursorPos instead, which seems to work OK:

if (PresentationSource.FromVisual(this) != null) {
	// Do a check to ensure the mouse isn't over any interop content
	var location = PointFromScreen(Interop.NativeMethods.GetCursorPosition());
	if (new Rect(new Point(), this.GetCurrentSize()).Contains(location))
		return;
}

The FromVisual call is needed because otherwise PointFromScreen will throw if the window is closed while the popup is open.

We'd rather not use a custom build from source, we tried this on a previous project and its a maintenance headache. But this isn't a critical problem so happy to wait until the next maintenance release without further workarounds.

Comments (1)

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

Hi Phil,

Thanks for the sample and tip.  We have added this sort of logic into the codebase for the upcoming maintenance release.  We just tweaked it a bit to ensure that we're not in XBAP and have full security rights to use PointFromScreen, etc.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.