简体   繁体   中英

Can't set the pushpin properties (WP8)

I have a map with Pushpin :

<maps:Map ZoomLevel="18" Height="575" x:Name="map1" Width="415" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,0,-10,0">
    <toolkit1:MapExtensions.Children>
        <toolkit1:Pushpin x:Name="push1" GeoCoordinate="" Content=""  Background="Gray" ContentTemplate="{StaticResource Template_Content}">
        </toolkit1:Pushpin>
    </toolkit1:MapExtensions.Children>
</maps:Map>

I try to set properties from the code:

map1.Center = currentObject.Coords;
push1.GeoCoordinate = currentObject.Coords;
push1.Content = currentObject.Name;

So Map works, but Pushpin returns NullReference Exception . What the reason and how to fix?

map1.Center = currentObject.Coords;
Pushpin pushpin = (Pushpin)this.FindName("push1");
pushpin .GeoCoordinate = currentObject.Coords;
pushpin .Content = currentObject.Name;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM