2012-03-28 6 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

関連する問題