gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:36:56 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com