mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-05-07 13:37:47 +00:00
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using Avalonia;
|
|
using Avalonia.Input;
|
|
using System;
|
|
|
|
namespace MapControl;
|
|
|
|
public partial class MapItem
|
|
{
|
|
Point? pointerPressedPosition;
|
|
|
|
protected override void OnPointerPressed(PointerPressedEventArgs e)
|
|
{
|
|
base.OnPointerPressed(e);
|
|
|
|
var point = e.GetCurrentPoint(null);
|
|
|
|
if (point.Properties.IsLeftButtonPressed)
|
|
{
|
|
pointerPressedPosition = point.Position;
|
|
}
|
|
|
|
e.Handled = true;
|
|
}
|
|
|
|
protected override void OnPointerReleased(PointerReleasedEventArgs e)
|
|
{
|
|
if (pointerPressedPosition.HasValue)
|
|
{
|
|
const double pointerMovementThreshold = 2d;
|
|
var position = e.GetCurrentPoint(null).Position;
|
|
|
|
// Perform selection only when no significant pointer movement occured.
|
|
//
|
|
if (Math.Abs(position.X - pointerPressedPosition.Value.X) <= pointerMovementThreshold &&
|
|
Math.Abs(position.Y - pointerPressedPosition.Value.Y) <= pointerMovementThreshold)
|
|
{
|
|
base.OnPointerReleased(e);
|
|
}
|
|
|
|
pointerPressedPosition = null;
|
|
}
|
|
|
|
e.Handled = true;
|
|
}
|
|
}
|