我正在使用 Bing map 控件显示一系列自定义图钉,代表不断移动和改变状态的对象。
使用数据绑定(bind),对象的各种属性正在按应有的方式更新,但由于某些原因,这不适用于它们的位置。
我将 map 绑定(bind)到一个 ObservableCollection:
<UserControl.Resources>
<DataTemplate x:Key="PushpinTemplate">
<v:CustomPushpin />
</DataTemplate>
</UserControl.Resources>
...
<m:Map Name="map">
<m:MapItemsControl ItemTemplate="{StaticResource PushpinTemplate}" ItemsSource="{Binding Objects}" />
</m:Map>
...并在 CustomPushpin 中:
<UserControl
...
m:MapLayer.Position="{Binding Location}" m:MapLayer.PositionOrigin="BottomCenter"
mc:Ignorable="d" d:DesignHeight="126" d:DesignWidth="85">
与所有其他属性一样,各个对象的位置是使用 INotifyPropertyChanged 实现的。
private Location _location;
public Location Location
{
get { return _location; }
set { _location = value; OnPropertyChanged("Location"); }
}
本地图移动时,无论是平移还是缩放,对象都会移动,但其他对象不会移动。
我不太清楚是我在这里做错了什么,还是 Bing map 控件有问题。
有什么想法吗?
最佳答案
我在这里找到了 Candritzky 的解决方法:Solution link with code
基本上,您必须将 ItemsPanel
更改为公开新 AttachedProperty
的自定义面板。对我来说它有效:)
关于wpf - Bing map - 图钉的自动更新位置绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4216433/