2012-03-27 54 views
1

它无法绑定经度和纬度吗?Bing地图经度纬度数据绑定

<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”是一个有效点,这是悉尼,如果我不是错了。

因为我发现地图没有显示我绑定的经度和纬度。它似乎是没有任何位置的原始地图。最重要的是,编译的过一段时间,就蹦出

未能分配财产“Bing.Maps.Location.Longitude

任何想法笏发生的呢?

+0

您尝试绑定的纬度和经度值在哪里?是否记得为包含地图的UI元素分配正确的DataContext?如果DataContext设置正确,您确定您的经度和纬度值是否有效? – 2012-03-27 17:58:38

+0

@BojinLi 感谢您的回复。这里是信息。 – 2012-03-28 01:10:40

回答

0

你粘贴的代码的一部分有点令人困惑,我可能会很密集,但我不知道你在用什么方法来使用CollectionViewSource。虽然你的经度和纬度属性似乎很可疑。根据Reference Documentation<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>将不会更新,即使您可能认为这是因为数据绑定。

+0

感谢您的回复。 对不起,乱码。其实我是从原来的例子修改。此外,我尝试了你给的解决方案。它似乎仍然是相同的“。我想我后来改变了我的经度和纬度。该地图在另一页上。我只是希望显示的位置,一旦我加载到页面中。所以不应该是一个问题。 >< – 2012-03-28 09:23:28