bool CheckMouseOutWindow() { #if alldbg || dbg DesktopPanelTool.Lib.Debug.WriteLine($"mouse directlyOver={Mouse.DirectlyOver}"); #endif if (Mouse.DirectlyOver is DependencyObject o && o != null) { var ancestor = WPFHelper.FindLogicalAncestor(o); #if alldbg || dbg DesktopPanelTool.Lib.Debug.WriteLine($"ancestor = {ancestor}"); #endif if (!(ancestor is Window w && AssociatedObject != w)) { return(false); } } POINT p = new POINT(); GetCursorPos(ref p); var x = p.X; var y = p.Y; if (_canMove) { GetWindowCoordinates(); } return(x < _left || x > _right || y <= _top || y >= _bottom); }