diff --git a/MapControl/Avalonia/MapItem.Avalonia.cs b/MapControl/Avalonia/MapItem.Avalonia.cs index 45300ad6..5d85601c 100644 --- a/MapControl/Avalonia/MapItem.Avalonia.cs +++ b/MapControl/Avalonia/MapItem.Avalonia.cs @@ -9,10 +9,19 @@ DependencyPropertyHelper.AddOwner(MapPanel.LocationProperty, null, (item, oldValue, newValue) => item.UpdateMapTransform(newValue)); + /// + /// Replaces ListBoxItem pointer event handling by not calling base.OnPointerPressed. + /// Setting e.Handled = true generates a PointerReleased event in the parent MapItemsControl, + /// which resembles the behavior of the ListBox base class. + /// protected override void OnPointerPressed(PointerPressedEventArgs e) { - (ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)? - .OnItemClicked(this, e.KeyModifiers.HasFlag(KeyModifiers.Control)); + if (!e.Handled) + { + e.Handled = true; + (ItemsControl.ItemsControlFromItemContainer(this) as MapItemsControl)? + .OnItemClicked(this, e.KeyModifiers.HasFlag(KeyModifiers.Control)); + } } } } diff --git a/MapControl/WPF/MapItem.WPF.cs b/MapControl/WPF/MapItem.WPF.cs index c410ed77..b5e8dcb0 100644 --- a/MapControl/WPF/MapItem.WPF.cs +++ b/MapControl/WPF/MapItem.WPF.cs @@ -18,9 +18,13 @@ namespace MapControl DefaultStyleKeyProperty.OverrideMetadata(typeof(MapItem), new FrameworkPropertyMetadata(typeof(MapItem))); } + /// + /// Replaces ListBoxItem mouse event handling by not calling base.OnMouseLeftButtonDown. + /// Setting e.Handled = true generates a MouseLeftButtonUp event in the parent MapItemsControl, + /// which resembles the behavior of the ListBox base class. + /// protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) { - // Prevent default handling in ListBoxItem by not calling base.OnMouseLeftButtonDown. if (!e.Handled) { e.Handled = true; @@ -29,9 +33,13 @@ namespace MapControl } } + /// + /// Replaces ListBoxItem mouse event handling by not calling base.OnMouseRightButtonDown. + /// Setting e.Handled = true generates a MouseRightButtonUp event in the parent MapItemsControl, + /// which resembles the behavior of the ListBox base class. + /// protected override void OnMouseRightButtonDown(MouseButtonEventArgs e) { - // Prevent default handling in ListBoxItem by not calling base.OnMouseRightButtonDown. e.Handled = true; } } diff --git a/MapControl/WinUI/MapItem.WinUI.cs b/MapControl/WinUI/MapItem.WinUI.cs index cc193396..30193541 100644 --- a/MapControl/WinUI/MapItem.WinUI.cs +++ b/MapControl/WinUI/MapItem.WinUI.cs @@ -33,9 +33,14 @@ namespace MapControl MapPanel.InitMapElement(this); } + /// + /// Replaces ListBoxItem pointer event handling by not calling base.OnPointerPressed. + /// Setting e.Handled = true generates a PointerReleased event in the parent MapItemsControl, + /// which differs from the behavior of the ListBox base class, where neither a PointerPressed + /// nor a PointerReleased is generated. + /// protected override void OnPointerPressed(PointerRoutedEventArgs e) { - // Prevent default handling in ListBoxItem by not calling base.OnPointerPressed. if (!e.Handled) { e.Handled = true; @@ -44,12 +49,6 @@ namespace MapControl } } - protected override void OnPointerReleased(PointerRoutedEventArgs e) - { - // Prevent default handling in ListBoxItem by not calling base.OnPointerReleased. - e.Handled = true; - } - protected override void OnApplyTemplate() { base.OnApplyTemplate();