Update MapItem.WinUI.cs

This commit is contained in:
ClemensFischer 2025-03-19 20:25:45 +01:00
parent c510e32014
commit 946d28a50c

View file

@ -28,10 +28,6 @@ namespace MapControl
item.UpdateMapTransform(newValue); item.UpdateMapTransform(newValue);
}); });
// Used to detect pointer movement between PointerPressed and
// PointerReleased in order to possibly cancel item selection.
//
private const float pointerMovementThreshold = 2f;
private Windows.Foundation.Point? pointerPressedPosition; private Windows.Foundation.Point? pointerPressedPosition;
public MapItem() public MapItem()
@ -49,10 +45,14 @@ namespace MapControl
protected override void OnPointerReleased(PointerRoutedEventArgs e) protected override void OnPointerReleased(PointerRoutedEventArgs e)
{ {
if (pointerPressedPosition.HasValue)
{
const float pointerMovementThreshold = 2f;
var p = e.GetCurrentPoint(null).Position; var p = e.GetCurrentPoint(null).Position;
if (pointerPressedPosition.HasValue && // Perform selection only when no significant pointer movement occured.
Math.Abs(p.X - pointerPressedPosition.Value.X) <= pointerMovementThreshold && //
if (Math.Abs(p.X - pointerPressedPosition.Value.X) <= pointerMovementThreshold &&
Math.Abs(p.Y - pointerPressedPosition.Value.Y) <= pointerMovementThreshold && Math.Abs(p.Y - pointerPressedPosition.Value.Y) <= pointerMovementThreshold &&
ItemsControl.ItemsControlFromItemContainer(this) is MapItemsControl mapItemsControl) ItemsControl.ItemsControlFromItemContainer(this) is MapItemsControl mapItemsControl)
{ {
@ -68,6 +68,8 @@ namespace MapControl
} }
pointerPressedPosition = null; pointerPressedPosition = null;
}
e.Handled = true; e.Handled = true;
} }