好的,简单的问题,但我还没有找到明显简单的答案! 我有一个带有地图集成的Windows Phone 7应用程序,地图上有一组图钉。图钉是自定义的(只是椭圆/圆形)。
不幸的是,自定义图钉的位置与地理位置“关闭”。当你放大时,它越来越接近准确,并且在最缩小的水平中是最远的。
我认为这是一个抵消问题。我查看了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>
答案 0 :(得分:8)
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}" />