我有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>
我尝试从代码中设置属性:
map1.Center = currentObject.Coords;
push1.GeoCoordinate = currentObject.Coords;
push1.Content = currentObject.Name;
所以Map
有效,但Pushpin
会返回NullReference Exception
。是什么原因以及如何解决?
答案 0 :(得分:2)
map1.Center = currentObject.Coords;
Pushpin pushpin = (Pushpin)this.FindName("push1");
pushpin .GeoCoordinate = currentObject.Coords;
pushpin .Content = currentObject.Name;