From 4f445493548ccef36280f94b541a346c7f69de65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Thu, 18 Jun 2026 04:09:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Tooltip=20=E5=9C=A8=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E9=95=BF=E6=8C=89=E5=B7=A6=E9=94=AE=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=94=B6=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wpf/Controls/ModernTooltipService.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Wpf/Controls/ModernTooltipService.cs b/Wpf/Controls/ModernTooltipService.cs index 341f135..aa676ee 100644 --- a/Wpf/Controls/ModernTooltipService.cs +++ b/Wpf/Controls/ModernTooltipService.cs @@ -111,15 +111,28 @@ public static class ModernTooltipService { if (sender is not FrameworkElement owner || !ReferenceEquals(owner, currentOwner)) return; lastMousePoint = e.GetPosition(owner); + if (e.LeftButton == MouseButtonState.Pressed && !IsPointInside(owner, lastMousePoint)) { + Close(true); + return; + } + if (GetFollowMouse(owner) && popup is { IsOpen: true }) UpdatePosition(owner, lastMousePoint); } private static void OnMouseLeave(object sender, MouseEventArgs e) { if (sender is not FrameworkElement owner || !ReferenceEquals(owner, currentOwner)) return; + // 避免 Tooltip 在文本区域长按左键时自动收回 + var point = e.GetPosition(owner); + if (e.LeftButton == MouseButtonState.Pressed && IsPointInside(owner, point)) return; + Close(true); } + private static bool IsPointInside(FrameworkElement owner, Point point) { + return point.X >= 0 && point.Y >= 0 && point.X <= owner.ActualWidth && point.Y <= owner.ActualHeight; + } + #endregion #region Tooltip 生命周期