WP7 Bing Map Pushpin - how to tweak the location of the custom pushpin?

我与影子孤独终老i 提交于 2019-12-04 11:15:57

A the PushPin class has a PositionOrigin property which indicates where the location point is relative the visual representation of the pin.

The default style use "BottomLeft" because of its shape it has a tick funneling to a point at its bottom left extremity.

However you are using a circle hence you would need move the PositionOrigin to the center. I would also recommend that you use a style rather than simply a template to "style" your push pin:-

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

Now your Xaml becomes:-

 <my2:Pushpin Name="pin1"
             Location="51.461326390697344, -0.9261151403188705"
             Content=""
             Style="{StaticResource PushpinControlTemplateBlue}" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!