Manipulation with left mouse button pressed only

This commit is contained in:
ClemensFischer 2023-01-06 15:59:06 +01:00
parent b95441011b
commit 13d6502f9d

View file

@ -23,6 +23,7 @@ namespace MapControl
public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register( public static readonly DependencyProperty MouseWheelZoomDeltaProperty = DependencyProperty.Register(
nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(0.25)); nameof(MouseWheelZoomDelta), typeof(double), typeof(Map), new PropertyMetadata(0.25));
private bool manipulationEnabled;
private double mouseWheelDelta; private double mouseWheelDelta;
public Map() public Map()
@ -34,6 +35,8 @@ namespace MapControl
| ManipulationModes.TranslateInertia; | ManipulationModes.TranslateInertia;
ManipulationDelta += OnManipulationDelta; ManipulationDelta += OnManipulationDelta;
PointerPressed += OnPointerPressed;
PointerReleased += OnPointerReleased;
PointerWheelChanged += OnPointerWheelChanged; PointerWheelChanged += OnPointerWheelChanged;
} }
@ -49,7 +52,21 @@ namespace MapControl
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{ {
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale); if (manipulationEnabled)
{
TransformMap(e.Position, e.Delta.Translation, e.Delta.Rotation, e.Delta.Scale);
}
}
private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
{
manipulationEnabled = e.Pointer.PointerDeviceType != PointerDeviceType.Mouse ||
e.GetCurrentPoint(this).Properties.IsLeftButtonPressed;
}
private void OnPointerReleased(object sender, PointerRoutedEventArgs e)
{
manipulationEnabled = false;
} }
private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e) private void OnPointerWheelChanged(object sender, PointerRoutedEventArgs e)