必应地图经度纬度数据绑定
本文关键字:纬度 数据绑定 经度 地图 | 更新日期: 2023-09-27 18:29:13
它无法绑定经纬度吗?
<bm:Map x:Name="EventMap" MapType="Birdseye" ZoomLevel="5"
Credentials="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" Height="480" Width="550"
HorizontalAlignment="Left">
<bm:Map.Center>
<bm:Location Latitude="{Binding Latitude}"
Longitude="{Binding Longitude}"/>
</bm:Map.Center>
</bm:Map>
这是与纬度和经度绑定的集合。
<CollectionViewSource
x:Name="itemsViewSource"
Source="{Binding EventItems}"
d:Source="{Binding EventItemGroups[0].EventItems, Source={d:DesignInstance Type=data:EventDataSource, IsDesignTimeCreatable=True}}"/>
我应该使用哪种数据类型?字符串?双倍还是其他?
private string _longitude = string.Empty;
public string Longitude
{
get { return this._longitude; }
set { this.SetProperty(ref this._longitude, value); }
}
private string _latitude = string.Empty;
public string Latitude
{
get { return this._latitude; }
set { this.SetProperty(ref this._latitude, value); }
}
我相信(经度("151.173248",(纬度("-33.840764"是一个有效的点,如果我没记错的话,那就是悉尼。
因为我发现地图没有显示我绑定的纬度和经度。它似乎是没有任何位置的原始地图。最重要的是,经过几次编译后,它弹出了
无法分配给属性"必应.地图.位置.经度
">
知道笏发生吗?
您粘贴的部分代码有点令人困惑,我可能很密集,但我不知道您使用CollectionViewSource
做什么。 不过,您的经度和纬度属性似乎很可疑。 根据参考文档,<bm:Map.Center>
采用一个Location
对象,而该对象又期望经度和纬度为双精度。 我很确定默认情况下将源字符串属性绑定到目标双精度属性将不起作用。 您必须指定一个值转换器。 在您的情况下,如果可能的话,只需对经度和纬度属性使用双精度:
private double _longitude = Double.NaN;
public double Longitude
{
get { return _longitude; }
set { SetProperty(ref _longitude, value); }
}
private double _latitude = Double.NaN;
public double Latitude
{
get { return _latitude; }
set { SetProperty(ref _latitude, value); }
}
我还注意到您的经度和纬度属性不是依赖项属性,并且您似乎没有实现INotifyPropertyChanged
接口,除非您在 SetProperty(( 中执行此操作 请记住,因此,如果您随后在代码中更改经度或纬度属性,您的<bm:Map.Center>
将不会更新, 即使您可能认为这是因为数据绑定。