【问题标题】:Bind location in bing maps xaml在 bing maps xaml 中绑定位置
【发布时间】:2013-11-27 02:20:28
【问题描述】:

如何在 bing 地图中绑定位置(经度和纬度)??

创建地图后,我想绑定多个位置,我尝试使用此代码但无法正常工作,为什么?

            <bm:Map Height="350" Credentials="xxxxxxxxxxxx" x:Name="Map" ZoomLevel="16" Margin="-27,28,10,78">

            <bm:Map.Center>
                <bm:Location Latitude="{Binding Longitude}" Longitude="{Binding Latitude}"/>
            </bm:Map.Center>

        </bm:Map>

【问题讨论】:

  • “我想绑定多个位置”,这是什么意思?您想在地图顶部显示对象(例如图钉)吗?
  • 在我的应用程序 20 个地方,我想显示每个地方的地图,所以我需要绑定这些地方的所有位置
  • 看看MapItemsControl。查找代码示例here

标签: c# wpf xaml windows-8 bing-maps


【解决方案1】:

您可以这样绑定项目集合。

<Maps:Map x:Name="Map" CredentialsProvider="BlaaBlaaBlaa" ZoomLevel="16" Margin="-27,28,10,78">
    <Maps:MapItemsControl ItemsSource="{Binding Locations}">
        <Maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <Maps:Pushpin Location="{Binding Location}" Content="{Binding Name}"
                                Background="{StaticResource PhoneAccentBrush}">

                </Maps:Pushpin>
            </DataTemplate>
        </Maps:MapItemsControl.ItemTemplate>
    </Maps:MapItemsControl>
</Maps:Map>

在此示例中,我有一个属性 Locations,它是 MapLocation 对象的集合

// DataContext
public ObservableCollection<MapLocation> Locations { get; private set; }

还有 MapLocation 类

public class MapLocation
{
    public GeoCoordinate Location { get; set; }
    public string Name { get; set; }
}

【讨论】:

  • 参考是什么?地图未定义!
  • 我在你使用“bm”的地方使用了“地图”。在您的 xaml 中将“地图”替换为“bm”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-19
相关资源
最近更新 更多