c# - 如何在 UWP 中创建 MapIcon 事件?

标签 c# xaml maps uwp

我想在我的 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 中放置更多元素,并且点击事件的处理方式略有不同 - 请查看 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
}

关于c# - 如何在 UWP 中创建 MapIcon 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377203/

相关文章:

python - 从 Python 字典中获取唯一第一次出现的更有效方法

jquery - 在按钮单击事件上使用 javascript 更改谷歌地图 iframe src 属性

c# - 有条件地在 Gridview 中显示 'Edit' 按钮

c# - 如何在安装时(或在编译时轻松配置)配置 Windows 服务的名称?

wpf - 如何为组框标题和组框内容提供单独的填充

c# - 不同计算机上的 WPF 应用程序不显示窗口

c# - 为什么在我的新类(class)中创建事件时出现错误?

c# - Linq 联盟 : How to add a literal value to the query?

c# - 在 xaml 中绑定(bind)矩形宽度和高度

android - 在安卓手机上显示巨大的平铺图像