From 41f44afd9f0294f2477f291625d193966b2c367a Mon Sep 17 00:00:00 2001 From: HerobrineXia Date: Thu, 23 Jul 2026 11:42:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dtooltip=E5=BC=B9?= =?UTF-8?q?=E7=AA=97=E5=9C=A8=E6=9F=90=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E4=B8=8D=E4=BC=9A=E6=AD=A3=E5=B8=B8=E6=B6=88=E5=A4=B1=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=88Meloong-Git/PCL#8917=EF=BC=8C@Peacoc?= =?UTF-8?q?k-Que=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wpf/Controls/ModernTooltipService.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Wpf/Controls/ModernTooltipService.cs b/Wpf/Controls/ModernTooltipService.cs index 9140429..f3f64c4 100644 --- a/Wpf/Controls/ModernTooltipService.cs +++ b/Wpf/Controls/ModernTooltipService.cs @@ -201,8 +201,8 @@ public static class ModernTooltipService { if (owner is not null) { BeginShow(owner, Mouse.GetPosition(owner)); - } else if (currentOwner is { IsEnabled: false }) { - Close(true); // 禁用的控件不会触发 MouseLeave,需要由其他元素收到的 MouseMove 主动关闭 + } else if (currentOwner is not null) { + Close(true); // 弹窗遮挡等情况可能不会触发原拥有者的 MouseLeave,需要由其他元素收到的 MouseMove 主动关闭 } } @@ -220,6 +220,14 @@ public static class ModernTooltipService { var owner = FindOwnerInAncestors(Mouse.DirectlyOver as DependencyObject); if (owner is not null) return owner; + // 重新从窗口根元素命中测试,避免弹窗出现后 Mouse.DirectlyOver 尚未刷新,继续命中已被遮挡的旧元素。 + if (PresentationSource.FromVisual(reference)?.RootVisual is UIElement root) { + var rootHit = root.InputHitTest(Mouse.GetPosition(root)) as DependencyObject; + owner = FindOwnerInAncestors(rootHit); + if (owner is not null) return owner; + if (rootHit is not null && !IsSameTreeBranch(rootHit, reference)) return null; + } + return reference.InputHitTest(Mouse.GetPosition(reference)) is DependencyObject hit ? FindOwnerInAncestors(hit) : null; @@ -307,6 +315,10 @@ public static class ModernTooltipService { private static void Show(FrameworkElement owner, Point point) { if (!ReferenceEquals(owner, currentOwner) || !CanShowModernTooltip(owner) || !TryGetToolTip(owner, out var content, out var sourceToolTip)) return; + if (!ReferenceEquals(owner, FindCurrentTooltipOwner(owner))) { + Close(false); + return; + } if (popup is null) { popupScale = new ScaleTransform(closedScale, closedScale);