Fixed touch input in Map.WinUI.cs

This commit is contained in:
Clemens 2022-01-24 23:29:35 +01:00
parent 69fd0753f7
commit bc8f1ce603

View file

@ -4,9 +4,11 @@
using System; using System;
#if WINUI #if WINUI
using Microsoft.UI.Input;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Input;
#else #else
using Windows.Devices.Input;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Input;
#endif #endif
@ -57,7 +59,8 @@ namespace MapControl
private void OnPointerPressed(object sender, PointerRoutedEventArgs e) private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{ {
if (CapturePointer(e.Pointer)) if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
CapturePointer(e.Pointer))
{ {
mousePosition = e.GetCurrentPoint(this).Position; mousePosition = e.GetCurrentPoint(this).Position;
} }
@ -65,7 +68,8 @@ namespace MapControl
private void OnPointerReleased(object sender, PointerRoutedEventArgs e) private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
{ {
if (mousePosition.HasValue) if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
mousePosition.HasValue)
{ {
mousePosition = null; mousePosition = null;
ReleasePointerCaptures(); ReleasePointerCaptures();
@ -74,7 +78,11 @@ namespace MapControl
private void OnPointerMoved(object sender, PointerRoutedEventArgs e) private void OnPointerMoved(object sender, PointerRoutedEventArgs e)
{ {
if (mousePosition.HasValue) // Perform translation by explicit Mouse input because with Manipulation pointer capture is
// lost when Map content changes, e.g. when a MapTileLayer or WmsImageLayer loads new images.
if (e.Pointer.PointerDeviceType == PointerDeviceType.Mouse &&
mousePosition.HasValue)
{ {
Point position = e.GetCurrentPoint(this).Position; Point position = e.GetCurrentPoint(this).Position;
var translation = position - mousePosition.Value; var translation = position - mousePosition.Value;