2012-03-28 61 views
3

我正在使用bingmap wpf。我在鼠標的點擊事件上創建了圖釘。現在我需要使其可拖動並根據圖釘位置跟蹤座標。任何人都有關於如何使圖釘可拖動的知識,以及在發佈時需要編寫哪些代碼更新的功能。如何使圖釘在bingmap中的地圖上拖動wpf

非常感謝你提前

回答

6
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; 
    } 
    } 
} 
+0

增加了鼠標向上停止拖動事件和一切工作的完美好先生,感謝您的快速回答:) – clamchoda 2013-07-05 19:23:43

相關問題