wpf - Bing map - 图钉的自动更新位置绑定(bind)

标签 wpf data-binding binding location bing-maps

我正在使用 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/

相关文章:

css - Angular:ngClass 属性中的条件始终被视为 true

回发时的 ASP.NET 数据绑定(bind)

c# - 属性绑定(bind)没有响应

c# - DataGrid.CellStyle 适用于 C# WPF 应用程序中的整行

wpf - WPF日历:自定义控件以显示日历周数

c# - 如何让 XAML 中的图像显示为它们的实际大小?

c# - 将 ListBox 的 ItemsSource 设置为其包含类的属性

c# - 将 WPF 视觉对象渲染为图像产生纯黑色图像

c# - WPF - 绑定(bind)到 ListView 项中的列表

wcf - 如何在 WCF 客户端的配置文件中使用 configSource 的多个位置