我在地图中显示图钉。
void GeoPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
_pushpins.Clear();
var cor = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
//Using the current coordinates define the Map center to those coordinates.
map.Center = cor;
_pushpins.Add(new PushpinModel
{
Description = "test",
Name = "test",
Location = new GeoCoordinate(e.Position.Location.Latitude,
e.Position.Location.Longitude),
DatetimeAdded = DateTime.Now
});
map.ZoomLevel = 15;
}
对于图钉加载需要一些时间,因为图钉移动到map中的当前位置。每次点击图钉时都会给出“NULL参考例外”。请告诉我如何处理它?</ p>
编辑:
private void Pushpin_Tap(object sender,
System.Windows.Input.GestureEventArgs e)
{
var _ppmodel = sender as Pushpin;
Pushpin pin = sender as Pushpin;
_id = _ppmodel.Tag.ToString();
ContextMenu contextMenu =
ContextMenuService.GetContextMenu(_ppmodel);
contextMenu.DataContext = _pushpins.Where
(c => (c.Location
== _ppmodel.Location)).FirstOrDefault();
if (contextMenu.Parent == null)
{
contextMenu.IsOpen = true;
}
}
虽然pushpin tap有时会获得null引用异常........