Windows phone 7 WP7 Bing地图图钉-如何调整自定义图钉的位置?
好的,简单的问题,但我还没有找到明显简单的答案! 我有一个集成了地图的WindowsPhone7应用程序,地图上有一组图钉。图钉是定制的(只是一个椭圆/圆) 不幸的是,自定义图钉的位置与地理位置“偏离”。当您放大时,它会越来越精确,并且在放大程度最高的关卡中距离最远 我认为这是一个抵消问题。我查看了RenderTransferMonorigin,但它似乎对我没有帮助 提前感谢,以下是相关代码:Windows phone 7 WP7 Bing地图图钉-如何调整自定义图钉的位置?,windows-phone-7,bing-maps,Windows Phone 7,Bing Maps,好的,简单的问题,但我还没有找到明显简单的答案! 我有一个集成了地图的WindowsPhone7应用程序,地图上有一组图钉。图钉是定制的(只是一个椭圆/圆) 不幸的是,自定义图钉的位置与地理位置“偏离”。当您放大时,它会越来越精确,并且在放大程度最高的关卡中距离最远 我认为这是一个抵消问题。我查看了RenderTransferMonorigin,但它似乎对我没有帮助 提前感谢,以下是相关代码: <phone:PhoneApplicationPage.Resources> &l
<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图钉
类具有一个位置原点
属性,该属性指示相对于图钉视觉表示的位置点
默认样式使用“BottomLeft”,因为它的形状在其左下端点有一个记号漏斗状的点
但是,您使用的是一个圆,因此需要将位置原点移动到中心。我还建议您使用样式而不是简单的模板来“样式”您的图钉:-
<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}" />
好的,这是一个非常令人印象深刻的答案。谢谢,干得好。