我有以下事件在geocoordinatewatcher对象位置更改事件时被触发。
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
//do the stuff here
}
现在当用户点击地图上的任何位置时,我想调用上面的方法并且每次都做同样的事情。 知道如何实现这个目标吗?
答案 0 :(得分:4)
手动调用事件处理程序:
var position = new GeoPosition<GeoCoordinate>(DateTimeOffset.Now, new GeoCoordinate(32, 64));
this.watcher_PositionChanged(this, new GeoPositionChangedEventArgs<GeoCoordinate>(position));
或者重写你的事件处理程序,将逻辑放在另一个方法中,然后调用它:
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
this.UpdatePosition(e.Position);
}
private void UpdatePosition(GeoCoordinate coordinates)
{
// Do the stuff here
}
这样,只要您愿意,就必须致电UpdatePosition
。我推荐这个解决方案,它比第一个更清洁。