WP7必应地图插图 - 如何调整自定义图钉的位置?

问题描述:

好的,简单的问题,但我还没有找到明显的简单答案呢! 我有一个带地图集成的Windows Phone 7应用程序,在地图上有一组图钉。图钉是自定义的(只是一个椭圆/圆形)。WP7必应地图插图 - 如何调整自定义图钉的位置?

不幸的是,自定义图钉的位置与地理位置“关闭”。当你放大时,它会越来越接近精确,并且在最缩小的层次上是最远的。

我认为这是一个抵消问题。我看着RenderTransformOnOrigin,但它似乎没有帮助我。预先

谢谢,这里是有关的代码:

<phone:PhoneApplicationPage.Resources> 
    <ControlTemplate x:Key="PushpinControlTemplateBlue" TargetType="my2:Pushpin"> 
     <Grid x:Name="ContentGrid" Width="34" Height="34" RenderTransformOrigin="0.5,0.5"> 
      <StackPanel Orientation="Vertical" > 
       <Grid MinHeight="31" MinWidth="29" Margin="0"> 
        <Ellipse Fill="Blue" 
          Margin="1" 
          HorizontalAlignment="Center" 
          VerticalAlignment="Center" 
          Width="20" 
          Height="20" 
          Stroke="White" 
          StrokeThickness="3" /> 
        <ContentPresenter HorizontalAlignment="Center" 
           Content="{TemplateBinding Content}" 
           ContentTemplate="{TemplateBinding ContentTemplate}" 
           Margin="4"/> 
       </Grid> 
      </StackPanel> 
     </Grid> 
    </ControlTemplate> 
</phone:PhoneApplicationPage.Resources> 


    <my1:Map Canvas.Left="16" Canvas.Top="13" CopyrightVisibility="Collapsed" CredentialsProvider="AtqOU-L_liZekzqR0mEG7dGDwswKnnXSoSmsVs6eGtAe7S9NZDiAtpAd1vgPfhxD" Height="521" LogoVisibility="Collapsed" Name="mapMain" ScaleVisibility="Collapsed" VerticalContentAlignment="Top" Visibility="Visible" Width="446" ZoomBarVisibility="Collapsed" BorderThickness="1" Background="Tomato"> 
     <my2:Pushpin Name="pin1" 
       Location="51.461326390697344, -0.9261151403188705" 
       Content="" 
       Template="{StaticResource PushpinControlTemplateBlue}" /> 
    </my1:Map> 

A中的PushPin类有一个PositionOrigin属性,其指示所述位置点是相对于销的视觉表示。

默认样式使用“BottomLeft”,因为它的形状有一个滴答漏斗到左下角的一个点。

但是,您正在使用圆形,因此您需要将PositionOrigin移动到中心位置。我也建议你使用的样式,而不是一个简单的模板,“风格”你的图钉: -

<ControlTemplate x:Key="PushpinControlTemplate" TargetType="my2:Pushpin"> 
     <Grid x:Name="ContentGrid" Width="34" Height="34" RenderTransformOrigin="0.5,0.5"> 
      <StackPanel Orientation="Vertical" > 
       <Grid MinHeight="31" MinWidth="29" Margin="0"> 
        <Ellipse Fill="{TemplateBinding Background}" 
          Margin="1" 
          HorizontalAlignment="Center" 
          VerticalAlignment="Center" 
          Width="20" 
          Height="20" 
          Stroke="{TemplateBinding Foreground}" 
          StrokeThickness="3" /> 
        <ContentPresenter HorizontalAlignment="Center" 
           Content="{TemplateBinding Content}" 
           ContentTemplate="{TemplateBinding ContentTemplate}" 
           Margin="4"/> 
       </Grid> 
      </StackPanel> 
     </Grid> 
    </ControlTemplate> 

<Style TargetType="my2:Pushpin" x:Key="PushpinControlTemplateBlue"> 
    <Setter Property="Template" Value="{StaticResource PushpinControlTemplate}" /> 
    <Setter Property="PositionOrigin" Value="Center" /> 
    <Setter Property="Background" Value="Blue" /> 
    <Setter Property="Foreground" Value="White" /> 
    <Setter Property="FontSize" Value="18" /> 
</Style> 

现在XAML中变为: -

<my2:Pushpin Name="pin1" 
      Location="51.461326390697344, -0.9261151403188705" 
      Content="" 
      Style="{StaticResource PushpinControlTemplateBlue}" /> 
+0

好吧,这是一个非常令人印象深刻的答案。谢谢你,干得好。 – pearcewg 2011-01-15 01:21:19