简体   繁体   English

UWP MapControl,如何处理地图元素选择和取消选择事件?

[英]UWP MapControl, how to handle map element select and unselect events?

In my UWP app I want user to allow select map element (to see detailed info) and unselect the map element by clicking empty are of the map.在我的 UWP 应用程序中,我希望用户允许选择地图元素(以查看详细信息)并通过单击地图的空白区域来取消选择地图元素。

In MapControl there are two events which I try to use:在 MapControl 中,我尝试使用两个事件:

MapElementClick(MapControl sender, MapElementClickEventArgs args) MapElementClick(MapControl sender, MapElementClickEventArgs args)

  • This event is fired when user clicks map element, I can handle map element selection here.当用户单击地图元素时会触发此事件,我可以在此处处理地图元素选择。

MapTapped(MapControl sender, MapInputEventArgs args) MapTapped(MapControl sender, MapInputEventArgs args)

  • This event is fired when user tap's map.当用户点击地图时会触发此事件。 I could handle map element unselection here but the problem is that this event is also fired when map element is tapped.我可以在这里处理取消选择地图元素,但问题是点击地图元素时也会触发此事件。

How I should handle this map element unselection?我应该如何处理这个地图元素取消选择? I think there is no way how I can cancel click/tap event bubble from MapElementClick() to prevent MapTapped() firing?我认为没有办法从 MapElementClick() 取消单击/点击事件气泡以防止 MapTapped() 触发?

This is my first answer here and I'm also kind of a C# newbie so be gentle pls :D这是我在这里的第一个答案,我也是一个 C# 新手,所以请保持温和:D

I had the same problem, and this is the workaround i did: I created two grids over my MapControl, one with margin, this is where you can show the detailed information, and an outer grid, which will detect the tap outside the information grid:我遇到了同样的问题,这是我所做的解决方法:我在我的 MapControl 上创建了两个网格,一个带有边距,这是您可以显示详细信息的地方,以及一个外部网格,它将检测信息网格外的水龙头:

<Grid>
    <maps:MapControl
       x:Name="MapControl"
       MapElementClick="MapControl_MapElementClick"
       MapServiceToken="YourMapToken">
    <Grid Name="OverlayGrid"
          Background="Transparent"
          Visibility="Collapsed"
          Tapped="OverlayGrid_Tapped"/>
    <Grid Name="InfoGrid"
          Margin="50,50,50,50"
          BorderBrush="Firebrick"
          BorderThickness="2"
          Background="White"
          Visibility="Collapsed"/>
</Grid>

In the codebehind:在代码隐藏中:

        private void MapControl_MapElementClick(MapControl sender, MapElementClickEventArgs args)
        {
            InfoGrid.Visibility = Visibility.Visible;
            OverlayGrid.Visibility = Visibility.Visible;
        }
        private void OverlayGrid_Tapped(object sender, TappedRoutedEventArgs e)
        {
            InfoGrid.Visibility = Visibility.Collapsed;
            OverlayGrid.Visibility = Visibility.Collapsed;
        }

This way whatever MapElement you click on will show you the grid where you can show your detailed information for the specific Mapelement, and if you click outside, both will be hidden.这样,无论您单击什么 MapElement,都会显示网格,您可以在其中显示特定 Mapelement 的详细信息,如果单击外部,则两者都将被隐藏。 Of course you can use any other layout control for showing the information you want.当然,您可以使用任何其他布局控件来显示您想要的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM