这里的第一个问题,到目前为止,我在阅读答案时得到了很大的帮助。不过,我找不到任何答案。所以来了..。
我们有一个必应地图,它的MapItemsControl绑定到ObservableCollection<Pushpin> Property。当向集合添加/移除项时,映射将得到正确更新。
现在我的问题是:如何更新/绑定集合中的Pushpin 的位置,以便在不通过移动/缩放?重新绘制地图的情况下将其反射到地图上。
下面是Map.xaml:
<phone:PhoneApplication ...
DataContext="{Binding Source={StaticResource Locator}, Path=Main}">
<maps:Map ...>
<maps:MapItemsControl ItemsSource="{Binding MapItems}"/>
</maps:Map>
</phone:PhoneApplication>MainViewModel.xaml:
#region MapItems
#region MapItems Property
/// <summary>
/// The <see cref="MapItems" /> property's name.
/// </summary>
public const string MapItemsPropertyName = "MapItems";
private ObservableCollection<Pushpin> _MapItems =
new ObservableCollection<Pushpin>();
/// <summary>
/// Sets and gets the MapItems property.
/// Changes to that property's value raise the PropertyChanged event.
/// </summary>
public ObservableCollection<Pushpin> MapItems
{
get
{
return _MapItems;
}
set
{
if (_MapItems == value)
{
return;
}
_MapItems = value;
RaisePropertyChanged(MapItemsPropertyName);
}
}
#endregion
#region OwnLocation
private Pushpin OwnLocation;
private void InitializeOwnLocation()
{
OwnLocation = new Pushpin()
{
Style = App.Current.Resources["OwnLocationStyle"] as Style
};
Binding b = new Binding {
Path = new PropertyPath("LastKnownLocation")
};
OwnLocation.SetBinding(Pushpin.LocationDependencyProperty, b);
MapItems.Add(OwnLocation);
}
#endregion
...
#endregionLastKnownLocation是在GeoCoordinateWatcher的PositionChanged中设置的
最新情况(30.5.2012 20.35)。LastKnownLocation属性的实现。
/// <summary>
/// The <see cref="LastKnownLocation" /> property's name.
/// </summary>
public const string LastKnownLocationPropertyName = "LastKnownLocation";
private GeoCoordinate _LastKnownLocation;
/// <summary>
/// Sets and gets the LastKnownLocation property.
/// Changes to that property's value raise the PropertyChanged event.
/// </summary>
public GeoCoordinate LastKnownLocation
{
get
{
return _LastKnownLocation;
}
private set
{
if (_LastKnownLocation == value)
{
return;
}
var oldValue = _LastKnownLocation;
_LastKnownLocation = value;
Settings["LastKnownLocation"] = _LastKnownLocation;
RaisePropertyChanged(LastKnownLocationPropertyName, oldValue, value, true);
}
}发布于 2015-01-27 07:14:24
正如我早些时候评论的那样,在谷歌搜索了很长时间后,我终于找到了一个似乎不再可用的解决办法。诀窍是在更改SetView后在地图视图上调用Pushpin.Location。
发布于 2012-10-29 07:16:13
地图控制上的x:Name= myMap
当你想重新绑定你的图钉时
设置myMap.Children.Clear()
那就重新加你的针。
您可以通知您的数据更改
https://stackoverflow.com/questions/10812608
复制相似问题