fix: 修复tooltip弹窗在某些情况下不会正常消失的问题(Meloong-Git/PCL#8917,@Peacock-Que)
This commit is contained in:
1 file changed
+14
-2
@@ -201,8 +201,8 @@ public static class ModernTooltipService {
|
|||||||
|
|
||||||
if (owner is not null) {
|
if (owner is not null) {
|
||||||
BeginShow(owner, Mouse.GetPosition(owner));
|
BeginShow(owner, Mouse.GetPosition(owner));
|
||||||
} else if (currentOwner is { IsEnabled: false }) {
|
} else if (currentOwner is not null) {
|
||||||
Close(true); // 禁用的控件不会触发 MouseLeave,需要由其他元素收到的 MouseMove 主动关闭
|
Close(true); // 弹窗遮挡等情况可能不会触发原拥有者的 MouseLeave,需要由其他元素收到的 MouseMove 主动关闭
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,6 +220,14 @@ public static class ModernTooltipService {
|
|||||||
var owner = FindOwnerInAncestors(Mouse.DirectlyOver as DependencyObject);
|
var owner = FindOwnerInAncestors(Mouse.DirectlyOver as DependencyObject);
|
||||||
if (owner is not null) return owner;
|
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
|
return reference.InputHitTest(Mouse.GetPosition(reference)) is DependencyObject hit
|
||||||
? FindOwnerInAncestors(hit)
|
? FindOwnerInAncestors(hit)
|
||||||
: null;
|
: null;
|
||||||
@@ -307,6 +315,10 @@ public static class ModernTooltipService {
|
|||||||
|
|
||||||
private static void Show(FrameworkElement owner, Point point) {
|
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, currentOwner) || !CanShowModernTooltip(owner) || !TryGetToolTip(owner, out var content, out var sourceToolTip)) return;
|
||||||
|
if (!ReferenceEquals(owner, FindCurrentTooltipOwner(owner))) {
|
||||||
|
Close(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (popup is null) {
|
if (popup is null) {
|
||||||
popupScale = new ScaleTransform(closedScale, closedScale);
|
popupScale = new ScaleTransform(closedScale, closedScale);
|
||||||
|
|||||||
Reference in new issue
Block a user