Merge pull request #341 from irihitech/dialog_drag

Make mask draggable when it's modal and cannot light dismiss.
This commit is contained in:
Dong Bin
2024-08-12 23:14:05 +08:00
committed by GitHub
3 changed files with 24 additions and 1 deletions

View File

@@ -119,6 +119,7 @@ public partial class OverlayDialogHost
control.RemoveHandler(OverlayFeedbackElement.ClosedEvent, OnDialogControlClosing);
control.RemoveHandler(DialogControlBase.LayerChangedEvent, OnDialogLayerChanged);
control.RemoveHandler(PointerPressedEvent, DragMaskToMoveWindow);
Children.Remove(control);

View File

@@ -166,6 +166,7 @@ public partial class OverlayDialogHost
_modalCount--;
IsInModalStatus = _modalCount > 0;
layer.Mask.RemoveHandler(PointerPressedEvent, ClickMaskToCloseDialog);
layer.Mask.RemoveHandler(PointerReleasedEvent, DragMaskToMoveWindow);
if (!IsAnimationDisabled)
{
var disappearAnimation = CreateAnimation(control.Bounds.Size, control.Position, false);

View File

@@ -114,9 +114,29 @@ public partial class OverlayDialogHost: Canvas
{
rec.AddHandler(PointerReleasedEvent, ClickMaskToCloseDialog);
}
else
{
rec.AddHandler(PointerPressedEvent, DragMaskToMoveWindow);
}
return rec;
}
private void DragMaskToMoveWindow(object? sender, PointerPressedEventArgs e)
{
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
return;
}
if (sender is PureRectangle mask)
{
var window = this.GetVisualAncestors().OfType<Window>().FirstOrDefault();
if(window is not null)
{
window.BeginMoveDrag(e);
}
}
}
private void ClickMaskToCloseDialog(object? sender, PointerReleasedEventArgs e)
{
if (sender is PureRectangle border)
@@ -126,6 +146,7 @@ public partial class OverlayDialogHost: Canvas
{
layer.Element.Close();
border.RemoveHandler(PointerReleasedEvent, ClickMaskToCloseDialog);
border.RemoveHandler(PointerPressedEvent, DragMaskToMoveWindow);
}
}
}