【问题标题】:UWP Pushpin ToolTip on click点击时的 UWP 图钉工具提示
【发布时间】:2017-08-01 03:49:03
【问题描述】:

我将 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>

现在工具提示始终可见。如何使其仅在单击 pin 时可见?

【问题讨论】:

标签: c# xaml uwp bing-maps


【解决方案1】:

一种选择可能是使用 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>

您只需为您的 ToolTip 命名,在开始时将其可见性设置为 Collapsed 并定义一个转换器,该转换器将产生与当前可见性相反的值,这样一旦用户再次单击,工具提示将消失。

【讨论】:

  • 尝试了相同的代码,但忘记绑定 TargetObject。无论如何它可以工作,但是当工具提示出现时椭圆正在移动
  • @miechoy 可能是因为 StackPanel 的宽度发生了变化,它变得居中了。
猜你喜欢
  • 1970-01-01
  • 2012-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多