我正在使用bingmap wpf。我在鼠标单击事件上创建了图钉。现在,我需要使其可拖动并根据图钉位置跟踪坐标。任何人都对如何使图钉可拖动以及在释放时需要编写代码以进行更新的功能有任何想法。
提前非常感谢你
最佳答案
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;
}
}
}