How to get pushpin to move around the map in bingmap wpf

I am working on bingmap wpf. I have created pushpins on mouse click. Now I need to get it to drag and track coordinates according to the pushpin location. Does anyone have an idea on how to force pushpin to be draggable and in which function we need to write the code to update when it is released.

Thank you in advance

+3


source to share


1 answer


Vector _mouseToMarker;
private bool _dragPin;
public Pushpin SelectedPushpin { get; set; }

void pin_MouseDown(object sender, MouseButtonEventArgs e)
{
  e.Handled = true;
  SelectedPushpin = sender as Pushpin;
  _dragPin = true;
  _mouseToMarker = Point.Subtract(
    map.LocationToViewportPoint(SelectedPushpin.Location), 
    e.GetPosition(map));
}

private void map_MouseMove(object sender, MouseEventArgs e)
{
  if (e.LeftButton == MouseButtonState.Pressed)
  {
    if (_dragPin && SelectedPushpin != null)
    {
      SelectedPushpin.Location = map.ViewportPointToLocation(
        Point.Add(e.GetPosition(map), _mouseToMarker));
      e.Handled = true;
    }
  }
}

      



+6


source







All Articles