Fixed: Closing a dialog returns TView to the user instead of occupying its parent.

This commit is contained in:
望尘空忧
2024-10-31 09:01:59 +08:00
parent f70e4de39c
commit 93a19e73e6

View File

@@ -35,6 +35,12 @@ public abstract class OverlayFeedbackElement : ContentControl
ClosedEvent.AddClassHandler<OverlayFeedbackElement>((o, e) => o.OnClosed(e));
}
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
Content = null;
}
public bool IsClosed
{
get => GetValue(IsClosedProperty);
@@ -133,9 +139,11 @@ public abstract class OverlayFeedbackElement : ContentControl
var left = Canvas.GetLeft(this);
var top = Canvas.GetTop(this);
var width = _windowEdge is WindowEdge.West or WindowEdge.NorthWest or WindowEdge.SouthWest
? Bounds.Width : _resizeDragStartBounds.Width;
? Bounds.Width
: _resizeDragStartBounds.Width;
var height = _windowEdge is WindowEdge.North or WindowEdge.NorthEast or WindowEdge.NorthWest
? Bounds.Height : _resizeDragStartBounds.Height;
? Bounds.Height
: _resizeDragStartBounds.Height;
var newBounds = CalculateNewBounds(left, top, width, height, diff, ContainerPanel?.Bounds, _windowEdge.Value);
Canvas.SetLeft(this, newBounds.Left);
Canvas.SetTop(this, newBounds.Top);
@@ -144,37 +152,49 @@ public abstract class OverlayFeedbackElement : ContentControl
AnchorAndUpdatePositionInfo();
}
private Rect CalculateNewBounds(double left, double top, double width, double height, Vector diff, Rect? containerBounds,
private Rect CalculateNewBounds(double left, double top, double width, double height, Vector diff,
Rect? containerBounds,
WindowEdge windowEdge)
{
diff = CoerceDelta(left, top, width, height, diff, containerBounds, windowEdge);
switch (windowEdge)
{
case WindowEdge.North:
top += diff.Y; height -= diff.Y;
top += diff.Y;
height -= diff.Y;
break;
case WindowEdge.NorthEast:
top += diff.Y; width += diff.X; height -= diff.Y;
top += diff.Y;
width += diff.X;
height -= diff.Y;
break;
case WindowEdge.East:
width += diff.X;
break;
case WindowEdge.SouthEast:
width += diff.X; height += diff.Y;
width += diff.X;
height += diff.Y;
break;
case WindowEdge.South:
height += diff.Y;
break;
case WindowEdge.SouthWest:
left += diff.X; width -= diff.X; height += diff.Y;
left += diff.X;
width -= diff.X;
height += diff.Y;
break;
case WindowEdge.West:
left += diff.X; width -= diff.X;
left += diff.X;
width -= diff.X;
break;
case WindowEdge.NorthWest:
left += diff.X; top += diff.Y; width -= diff.X; height -= diff.Y;
left += diff.X;
top += diff.Y;
width -= diff.X;
height -= diff.Y;
break;
}
return new Rect(left, top, width, height);
}