修复 Popup 弹出问题

This commit is contained in:
polarboy 2024-07-24 12:53:10 +08:00
parent fe24299338
commit 25563d6f3e
2 changed files with 14 additions and 8 deletions

View File

@ -379,6 +379,10 @@ public abstract class AbstractPopup : Control, IPopupHostProvider
protected virtual void NotifyClosed() {}
protected internal virtual void NotifyPopupRootAboutToShow(PopupRoot popupRoot) {}
protected Control? GetEffectivePlacementTarget()
{
return PlacementTarget ?? this.FindLogicalAncestorOfType<Control>();
}
/// <summary>
/// Opens the popup.
@ -390,7 +394,7 @@ public abstract class AbstractPopup : Control, IPopupHostProvider
return;
}
var placementTarget = PlacementTarget ?? this.FindLogicalAncestorOfType<Control>();
var placementTarget = GetEffectivePlacementTarget();
if (placementTarget == null) {
_isOpenRequested = true;
@ -654,8 +658,10 @@ public abstract class AbstractPopup : Control, IPopupHostProvider
private void HandlePositionChange()
{
if (_openState != null) {
var placementTarget = PlacementTarget ?? this.FindLogicalAncestorOfType<Control>();
if (placementTarget == null) return;
var placementTarget = GetEffectivePlacementTarget();
if (placementTarget == null) {
return;
}
_openState.PopupHost.ConfigurePosition(
placementTarget,
Placement,

View File

@ -80,9 +80,9 @@ public class Popup : AbstractPopup
protected override void NotifyPopupHostCreated(IPopupHost popupHost)
{
base.NotifyPopupHostCreated(popupHost);
if (PlacementTarget is not null) {
var toplevel = TopLevel.GetTopLevel(PlacementTarget);
var placementTarget = GetEffectivePlacementTarget();
if (placementTarget is not null) {
var toplevel = TopLevel.GetTopLevel(placementTarget);
if (toplevel is null) {
throw new InvalidOperationException(
"Unable to create shadow layer, top level for PlacementTarget is null.");
@ -207,7 +207,7 @@ public class Popup : AbstractPopup
VerticalOffset = offsetY;
var direction = PopupUtils.GetDirection(Placement);
var placementTarget = PlacementTarget ?? this.FindLogicalAncestorOfType<Control>();
var placementTarget = GetEffectivePlacementTarget();
if (placementTarget is null) {
throw new InvalidOperationException("Placement mode is not Pointer and PlacementTarget is null");
}