Select to view content in your preferred language

Pan using middle mouse button

666
1
Jump to solution
02-09-2022 05:12 AM
TimScheiber
Occasional Contributor

I'm looking for a way to pan using the middle mouse button. In ArcMap you can pan around the map while being in a selection mode and I want the same behavior in my WPF application.

I have found a few other questions that ask the same thing, but are not really answered.

Is there any way to do this using the Runtime SDK for .NET?

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
dotMorten_esri
Esri Notable Contributor

How's this:

var peer = new Esri.ArcGISRuntime.UI.Controls.MapViewAutomationPeer(mapView);
Point? start = null;
mapView.MouseDown += (s, e) =>
{
    if (e.ChangedButton == MouseButton.Middle)
        start = e.GetPosition(mapView);
};
mapView.MouseUp += (s, e) =>
{
    if (e.ChangedButton == MouseButton.Middle)
    {
        start = null;
        peer.Complete();
    }
};
mapView.PreviewMouseMove += (s, e) =>
{
    if (e.MiddleButton == MouseButtonState.Pressed && start.HasValue)
    {
        var p = e.GetPosition(mapView);
            peer.Pan(p.X - start.Value.X, p.Y - start.Value.Y);
        start = p;
    }
};

View solution in original post

1 Reply
dotMorten_esri
Esri Notable Contributor

How's this:

var peer = new Esri.ArcGISRuntime.UI.Controls.MapViewAutomationPeer(mapView);
Point? start = null;
mapView.MouseDown += (s, e) =>
{
    if (e.ChangedButton == MouseButton.Middle)
        start = e.GetPosition(mapView);
};
mapView.MouseUp += (s, e) =>
{
    if (e.ChangedButton == MouseButton.Middle)
    {
        start = null;
        peer.Complete();
    }
};
mapView.PreviewMouseMove += (s, e) =>
{
    if (e.MiddleButton == MouseButtonState.Pressed && start.HasValue)
    {
        var p = e.GetPosition(mapView);
            peer.Pan(p.X - start.Value.X, p.Y - start.Value.Y);
        start = p;
    }
};