Input event handling in WinUI Map and MapItem

This commit is contained in:
ClemensFischer 2025-03-19 16:06:33 +01:00
parent 86f307359f
commit 58ce17db46
2 changed files with 16 additions and 11 deletions

View file

@ -21,7 +21,7 @@ namespace MapControl
DependencyPropertyHelper.Register<Map, double>(nameof(MouseWheelZoomDelta), 0.25);
private double mouseWheelDelta;
private bool manipulationEnabled;
private bool? manipulationEnabled;
public Map()
{
@ -34,6 +34,7 @@ namespace MapControl
ManipulationDelta += OnManipulationDelta;
ManipulationCompleted += OnManipulationCompleted;
PointerPressed += OnPointerPressed;
PointerMoved += OnPointerMoved;
PointerWheelChanged += OnPointerWheelChanged;
}
@ -49,7 +50,7 @@ namespace MapControl
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
if (manipulationEnabled)
if (manipulationEnabled.HasValue && manipulationEnabled.Value)
{
if (e.PointerDeviceType == PointerDeviceType.Mouse)
{
@ -64,7 +65,7 @@ namespace MapControl
private void OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
manipulationEnabled = false;
manipulationEnabled = null;
}
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
@ -76,6 +77,17 @@ namespace MapControl
e.KeyModifiers == VirtualKeyModifiers.None;
}
private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
{
// Set manipulationEnabled when no PointerPressed was received.
//
if (!manipulationEnabled.HasValue &&
e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
{
manipulationEnabled = e.KeyModifiers == VirtualKeyModifiers.None;
}
}
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)
{
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse)

View file

@ -45,11 +45,6 @@ namespace MapControl
pointerPressedPosition = e.GetCurrentPoint(null).Position;
base.OnPointerPressed(e);
// Unsetting e.Handled enables PointerPressed event handlers
// and PointerPressed handling in class Map.
//
e.Handled = false;
}
protected override void OnPointerReleased(PointerRoutedEventArgs e)
@ -71,9 +66,7 @@ namespace MapControl
}
}
// Unsetting e.Handled enables PointerReleased event handlers.
//
e.Handled = false;
e.Handled = true;
}
protected override void OnApplyTemplate()