如何获取MapElement点击类型(MapControl) (Windows 10 universal app)

How to get MapElement tapped type (MapControl) (Windows 10 universal app)

有了新的 Windows 10 系列设备,visual studio 开始有了新的事件处理程序。 MapElementClickEventArgs,它允许开发人员从点击的 MapElement 获取操作,但我想为所选的每种类型的 MapElement 提供不同的操作。例如:MapIcons 的动作和 MapPolygons 的不同动作

有人知道我怎么无法获取被窃听的实体类型吗?

这是这个处理器的型号:

private void MapControl1_MapElementClick(MapControl sender, MapElementClickEventArgs args) { }

在 Windows10 地图控件中,将返回与您在地图上单击的位置相交的所有 MapElements 的数组。如果循环遍历每个元素,您可以使用 "is" 关键字检查它是 MapIcon 还是其他 MapElement。这是您的代码的扩展版本:

private void MapControl1_MapElementClick(MapControl sender, MapElementClickEventArgs args)
{
    foreach (var e in args.MapElements)
    {
        if (e is MapPolygon)
        {
            var poly = e as MapPolygon;
            //Is MapPolygon
        }
        else if (e is MapPolyline)
        {
            var poly = e as MapPolyline;
            //Is MapPolyline
        }
        else if (e is MapIcon)
        {
            var icon = e as MapIcon;
            //Is MapIcon
        }
    }
}