From 86f307359ffea56ca671fde393efcbb8cdd38d67 Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Wed, 19 Mar 2025 15:27:27 +0100 Subject: [PATCH] Input event handling in WinUI Map and MapItem. --- MBTiles/WinUI/MBTiles.WinUI.csproj | 2 +- MapControl/WinUI/Map.WinUI.cs | 18 +++--------------- MapControl/WinUI/MapControl.WinUI.csproj | 3 +-- MapControl/WinUI/MapItem.WinUI.cs | 12 ++++++++++-- .../WinUI/MapProjections.WinUI.csproj | 2 +- MapUiTools/WinUI/MapUiTools.WinUI.csproj | 2 +- SampleApps/WinUiApp/WinUiApp.csproj | 2 +- 7 files changed, 18 insertions(+), 23 deletions(-) diff --git a/MBTiles/WinUI/MBTiles.WinUI.csproj b/MBTiles/WinUI/MBTiles.WinUI.csproj index c2536b36..0a6aec85 100644 --- a/MBTiles/WinUI/MBTiles.WinUI.csproj +++ b/MBTiles/WinUI/MBTiles.WinUI.csproj @@ -21,7 +21,7 @@ - + diff --git a/MapControl/WinUI/Map.WinUI.cs b/MapControl/WinUI/Map.WinUI.cs index 360e1e80..9f8eff2c 100644 --- a/MapControl/WinUI/Map.WinUI.cs +++ b/MapControl/WinUI/Map.WinUI.cs @@ -21,7 +21,7 @@ namespace MapControl DependencyPropertyHelper.Register(nameof(MouseWheelZoomDelta), 0.25); private double mouseWheelDelta; - private bool? manipulationEnabled; + private bool manipulationEnabled; public Map() { @@ -34,7 +34,6 @@ namespace MapControl ManipulationDelta += OnManipulationDelta; ManipulationCompleted += OnManipulationCompleted; PointerPressed += OnPointerPressed; - PointerMoved += OnPointerMoved; PointerWheelChanged += OnPointerWheelChanged; } @@ -50,7 +49,7 @@ namespace MapControl private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { - if (manipulationEnabled.HasValue && manipulationEnabled.Value) + if (manipulationEnabled) { if (e.PointerDeviceType == PointerDeviceType.Mouse) { @@ -65,7 +64,7 @@ namespace MapControl private void OnManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) { - manipulationEnabled = null; + manipulationEnabled = false; } private void OnPointerPressed(object sender, PointerRoutedEventArgs e) @@ -77,17 +76,6 @@ 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) diff --git a/MapControl/WinUI/MapControl.WinUI.csproj b/MapControl/WinUI/MapControl.WinUI.csproj index ebd4e59e..334910dd 100644 --- a/MapControl/WinUI/MapControl.WinUI.csproj +++ b/MapControl/WinUI/MapControl.WinUI.csproj @@ -22,8 +22,7 @@ - - + diff --git a/MapControl/WinUI/MapItem.WinUI.cs b/MapControl/WinUI/MapItem.WinUI.cs index fec42d25..9be45c94 100644 --- a/MapControl/WinUI/MapItem.WinUI.cs +++ b/MapControl/WinUI/MapItem.WinUI.cs @@ -42,8 +42,14 @@ namespace MapControl protected override void OnPointerPressed(PointerRoutedEventArgs e) { - base.OnPointerPressed(e); 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) @@ -65,7 +71,9 @@ namespace MapControl } } - e.Handled = true; + // Unsetting e.Handled enables PointerReleased event handlers. + // + e.Handled = false; } protected override void OnApplyTemplate() diff --git a/MapProjections/WinUI/MapProjections.WinUI.csproj b/MapProjections/WinUI/MapProjections.WinUI.csproj index f5c4902b..f9a7348f 100644 --- a/MapProjections/WinUI/MapProjections.WinUI.csproj +++ b/MapProjections/WinUI/MapProjections.WinUI.csproj @@ -21,7 +21,7 @@ - + diff --git a/MapUiTools/WinUI/MapUiTools.WinUI.csproj b/MapUiTools/WinUI/MapUiTools.WinUI.csproj index 8d488c1b..3318126c 100644 --- a/MapUiTools/WinUI/MapUiTools.WinUI.csproj +++ b/MapUiTools/WinUI/MapUiTools.WinUI.csproj @@ -17,7 +17,7 @@ - + diff --git a/SampleApps/WinUiApp/WinUiApp.csproj b/SampleApps/WinUiApp/WinUiApp.csproj index a8112acd..853d94c5 100644 --- a/SampleApps/WinUiApp/WinUiApp.csproj +++ b/SampleApps/WinUiApp/WinUiApp.csproj @@ -36,7 +36,7 @@ - +