c# - 如何使图钉可在 bingmap wpf 中的 map 上拖动

标签 c# wpf bing-maps bing-api

我正在研究 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;
    }
  }
}

关于c# - 如何使图钉可在 bingmap wpf 中的 map 上拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9906335/

相关文章:

c# - Catel - CommandManager 未传递 CommandParameter

c# - EF 一对一主要关系错误

.net - WPF 运行时 xaml/表单设计器

c# - 属性更改时属性未将值传回文本框的问题

javascript - 使用来自数据库的位置坐标在 Bing map 上实现 pointInpolygon 搜索算法

c# - 如何更改 BingMaps for Silverlight 中自定义图钉内元素的大小

c# - 使用 XmlSerializer 反序列化 List<int> 导致额外的项目

c# - WPF - 发送 key Redux

c# - ValueTuple 不支持 DisplayMemberPath。组合框,WPF

google-maps - 检查点是否在多边形( map )中