If PointerCapture is lost, end dragging to prevent inconsistency when returning
Add Escape Key as an option for cancelling an unintended drag
This commit is contained in:
David O'Rourke 2024-03-28 08:44:07 +00:00
Родитель e28bcccc1e
Коммит 90fb114309
1 изменённых файлов: 27 добавлений и 7 удалений

Просмотреть файл

@ -54,6 +54,7 @@ namespace RectPainter.Controls
PointerMoved += PaintControl_PointerMoved;
PointerPressed += PaintControl_PointerPressed;
PointerReleased += PaintControl_PointerReleased;
PointerCaptureLost += PaintControl_PointerCaptureLost;
SizeChanged += PaintControl_SizeChanged;
KeyDownEvent.AddClassHandler<TopLevel>(PaintControl_KeyDown, handledEventsToo: true);
@ -97,13 +98,28 @@ namespace RectPainter.Controls
{
if (Vm != null)
{
// Finish dragging
if (Vm.Dragging == true)
{
// Finish dragging
Vm.Dragging = false;
// Paint a new rectangle
Vm.AddRectangle();
// Request the updated image be rendered
InvalidateVisual();
}
}
}
private void PaintControl_PointerCaptureLost(object? sender, PointerCaptureLostEventArgs e)
{
if (Vm != null)
{
// finish Dragging
Vm.Dragging = false;
// Paint a new rectangle
Vm.AddRectangle();
// Request the updated image be rendered
// Request the image be rendered (to clear any marquee)
InvalidateVisual();
}
}
@ -120,12 +136,11 @@ namespace RectPainter.Controls
}
}
private void PaintControl_KeyDown(object? sender, KeyEventArgs e)
{
if (Vm != null)
{
// Change rectangle color
// Change rectangle color or cancel dragging
// Request the updated image be rendered, in case there is a marquee
switch (e.Key)
{
@ -143,6 +158,11 @@ namespace RectPainter.Controls
Vm.Blue = 255;
InvalidateVisual();
break;
case Key.Escape:
Vm.Dragging = false;
InvalidateVisual();
break;
}
}
}