none
The location of pushpin with custom control template is not correctly maintained on zooming RRS feed

  • Question

  • Hi,

    I'm using Bing Maps SDKs for Windows Store apps to develop a  C#/XAML  App. I put a pushpin with my custom control template on map:

        <Page.Resources>
            <ControlTemplate x:Key="pushpin"
                             TargetType="Maps:Pushpin">
                <Canvas>
                    <Image Name="Image"
                           Height="48"
                           Width="48"
                           Source="Assets/Images/Sample.png"
                           Stretch="None" />
                    <TextBlock Canvas.Left="60"
                               Text="Location"
                               Canvas.Top="10"
                               Foreground="Black"/>
                </Canvas>
            </ControlTemplate>
    
        </Page.Resources>
        
    ...
    
            <Maps:Map x:Name="map"
                      Margin="60,0,0,0"
                      Credentials="{StaticResource BingCredentials}"
                      ShowScaleBar="True"
                      ZoomLevel="10">
                <Maps:Map.Children>
                    <Maps:Pushpin x:Name="pushPin" Template="{StaticResource ResourceKey=pushpin}">
                        <Maps:MapLayer.Position>
                            <Maps:Location Latitude="46.94922"
                                         Longitude="7.4462" />
                            </Maps:MapLayer.Position>
                    </Maps:Pushpin>
                </Maps:Map.Children>
            </Maps:Map>
    
     

    The pushpin is placed on the map,  but when I start zooming it moves to wrong location, so for example a pushpin put in the Switzerland will be shown over Italy. The problem doesn't exist with default pushpin template.  I suppose I have to modify my template and bind it to the correct position, but i was not able to figure out how to do it.

    Anyone knows a workaround?

    Wednesday, October 10, 2012 10:31 AM

Answers

  • This issue is begin caused as the pushpin is likely anchored to a different part on your control than you expect. you can correct this by offsetting the xaml control using margins.

    http://rbrundritt.wordpress.com

    Wednesday, October 10, 2012 1:33 PM
  • Or setting the MapLayer.PositionAnchor attached property.
    Wednesday, October 10, 2012 3:37 PM

All replies

  • This issue is begin caused as the pushpin is likely anchored to a different part on your control than you expect. you can correct this by offsetting the xaml control using margins.

    http://rbrundritt.wordpress.com

    Wednesday, October 10, 2012 1:33 PM
  • Or setting the MapLayer.PositionAnchor attached property.
    Wednesday, October 10, 2012 3:37 PM
  • Thanks, PostitionAnchor has helped
    Thursday, October 11, 2012 7:26 AM
  • Krzysztof, this is a question I had related to your code above, I'm using it to set my pushpin template as well. How are you setting the TextBlock Text property from your C# code? Is it possible to set a ControlTemplate's element's properties from code?
    Saturday, October 20, 2012 12:10 AM