单击UWP图钉工具提示

时间:2017-03-10 17:37:34

标签: c# xaml uwp bing-maps

我将Bing地图添加到了我的UWP视图中。我创建了自定义MapItemControl。 我想点击我的图钉时显示工具提示。

这是我做的:

  <my:MapControl Name="Map" Center="{Binding Location, Converter={StaticResource LocationToGeopoint}}" ZoomLevel="{Binding ZoomLevel}">
            <my:MapItemsControl ItemsSource="{Binding Offers}" >
                <my:MapItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel   my:MapControl.NormalizedAnchorPoint="0.5,1"   
                                      my:MapControl.Location="{Binding Location, Converter={StaticResource LocationToGeopoint}}"   
                                      Width="Auto" Height="Auto"  >
                            <Grid  Height="25" Width="25" Name="ContentGrid">
                                <Ellipse Fill="White" Height="Auto" Width="Auto"
                                         Stroke="Red"
                                         StrokeThickness="8"/>
                                <interactivity:Interaction.Behaviors>
                                    <core:EventTriggerBehavior EventName="PointerPressed">
                                        <core:InvokeCommandAction 
                                            CommandParameter="{Binding Id}"
                                            Command="{Binding ElementName=Map, Path=DataContext.PushpinTapped}"  />
                                    </core:EventTriggerBehavior>
                                </interactivity:Interaction.Behaviors>
                            </Grid>
                            <Path Data="M33.4916,35.3059 L42.1937,35.3059 L38.1973,40.6036 z" Fill="Red" HorizontalAlignment="Center" Height="6.302" Margin="0,-1,0,0" Stretch="Fill" UseLayoutRounding="False" Width="9.702"/>
                            <ToolTip   Style="{StaticResource MyToolTipStyle}"/>
                        </StackPanel>
                    </DataTemplate>
                </my:MapItemsControl.ItemTemplate>

            </my:MapItemsControl>
        </my:MapControl>

现在,ToolTip始终可见。如何仅在单击引脚时才能使其可见?

1 个答案:

答案 0 :(得分:2)

一个选项可能是使用 ChangePropertyAction - 示例:

<my:MapControl Name="Map" Center="{Binding Location, Converter={StaticResource LocationToGeopoint}}" ZoomLevel="{Binding ZoomLevel}">
    <my:MapItemsControl ItemsSource="{Binding Offers}" >
        <my:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <StackPanel   my:MapControl.NormalizedAnchorPoint="0.5,1"   
                              my:MapControl.Location="{Binding Location, Converter={StaticResource LocationToGeopoint}}"   
                              Width="Auto" Height="Auto"  >
                    <Grid  Height="25" Width="25" Name="ContentGrid">
                        <Ellipse Fill="White" Height="Auto" Width="Auto"
                                 Stroke="Red"
                                 StrokeThickness="8"/>
                        <interactivity:Interaction.Behaviors>
                            <core:EventTriggerBehavior EventName="PointerPressed">
                                <core:InvokeCommandAction 
                                      CommandParameter="{Binding Id}"
                                      Command="{Binding ElementName=Map, Path=DataContext.PushpinTapped}"  />
                                <core:ChangePropertyAction TargetObject="{Binding ElementName=myTooltip}" 
                                      PropertyName="Visibility" Value="{Binding ElementName=myTooltip, Path=Visibility, Converter={StaticResource InvertConverter}}"/>

                            </core:EventTriggerBehavior>
                        </interactivity:Interaction.Behaviors>
                    </Grid>
                    <Path Data="M33.4916,35.3059 L42.1937,35.3059 L38.1973,40.6036 z" Fill="Red" HorizontalAlignment="Center" Height="6.302" Margin="0,-1,0,0" Stretch="Fill" UseLayoutRounding="False" Width="9.702"/>
                    <ToolTip x:Name="myTooltip" Style="{StaticResource MyToolTipStyle}" Visibility=Collapsed"/>
                </StackPanel>
            </DataTemplate>
        </my:MapItemsControl.ItemTemplate>
    </my:MapItemsControl>
</my:MapControl>

您只需要为工具提示命名,在启动时将其可见性设置为 Collapsed ,并定义一个与当前可见性相反的转换器,以便一次用户再次单击,工具提示将消失。