我想将图钉添加到可点击的MapControl中。由于Windows 8.1图钉类不再可用,因此UWP为我们提供了一个称为ImageIcon的东西。这是我的代码:

BasicGeoposition bg = new BasicGeoposition() { Latitude = 52.280, Longitude = 20.972 };
Geopoint snPoint = new Geopoint(bg);
MapIcon mapIcon1 = new MapIcon();
mapIcon1.Location = snPoint;
mapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
MyMap.MapElements.Add(mapIcon1);

如何进行事件处理(如点击或单击)?

先感谢您

最佳答案

在UWP中,您可以在 map 中放置更多元素,而click事件的处理方式几乎没有什么不同-请查看MapControl.MapElementClick。事件由MapControl处理-因此您无需订阅每个 map 元素-提及的事件将返回被单击元素的列表。示例代码如下所示:

<map:MapControl Name="MyMap" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" MapElementClick="MyMap_MapElementClick"/>

private void MyMap_MapElementClick(Windows.UI.Xaml.Controls.Maps.MapControl sender, Windows.UI.Xaml.Controls.Maps.MapElementClickEventArgs args)
{
    MapIcon myClickedIcon = args.MapElements.FirstOrDefault(x => x is MapIcon) as MapIcon;
    // do rest
}

10-08 05:18