2017-03-10 4 views
1

私は私のUWP ViewにBing Mapsを追加しました。私はカスタムMapItemControlを作成しました。 ピンをクリックしたときにツールチップを表示したいと思います。ここでUWP Pushpin ToolTip on click

は私がやったことです:

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

今、ツールヒントは、すべての時間表示されます。ピンをクリックしたときにのみ、どのように表示させることができますか?

+0

[infobox](https://msdn.microsoft.com/en-us/library/mt750272.aspx)と同様ですか? –

答えて

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> 

、開始時に折りたたまへの可視性を設定し、意志コンバータを定義します現在の表示の反対の値を作成します。その結果、ユーザーが再度クリックすると、ツールチップが消えるようになります。

+0

同じコードを試しましたが、TargetObjectをバインドするのを忘れていました。とにかく動作しますが、ツールチップが表示されたら楕円が動いています – miechooy

+0

@miechooyおそらくStackPanelの幅が変わって、それが巻き戻されるためです。 – Romasz