在 Windows Phone 中将图钉绑定到 Bing 地图 [英] Binding Pushpins to Bing Maps in Windows Phone
问题描述
所以我需要一些帮助 - 一些关于如何做的教程.
So I need some help here - Some tutorials on how to do it.
我正在尝试为我的应用创建位置页面
I am trying to create a location page for my app
我需要知道如何将两个 xml 节点绑定到一个图钉列表中,然后当用户单击它们时,它将值带到另一个页面.
I need to know how to also bind two xml nodes into one for a list of pushpins and then when the user clicks on them it takes the value to another page.
我可以填充 XML 和地图.以下是我目前如何获得停靠点.
I can populate the XML and the map. Below is how i currently get the stops.
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
if (e.Result != null)
{
XDocument doc = XDocument.Parse(e.Result);
XNamespace ns = "http://schemas.datacontract.org/2004/07/BusExpress.ClassLibrary";
var locations = (from n in doc.Descendants(ns + "ArrayOfStop")
select new RootContainer
{
Location = (from s in n.Elements(ns + "Stop")
select new Location
{
latitude = s.Element(ns + "lat").Value,
longitude = s.Element(ns + "long").Value,
}).ToList()
}).Single();
// listBusStops.ItemsSource = locations.Location;
// Do something with the list of Route Names in routeNames
}
}
}
如何将其从一个 xml 提要转换为多个图钉.
How can i convert that into multiple Push pins from one xml feed.
推荐答案
更新:添加了更多代码,以及工作演示和完整源代码的链接.
Update: Added more code, as well as a link to a working demo and complete source.
注意:通过我的博客提供的演示.
您可以构建一个数据模板来表示图钉在地图上的显示方式.
You can build a Data Template to represent how the push pins should be shown on the map.
例如:
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="PinItemTemplate">
<my:Pushpin Location="{Binding Location}"
MouseLeftButtonUp="Pushpin_MouseLeftButtonUp_1"
Content="{Binding Id}">
</my:Pushpin>
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
然后,您可以将 bing 地图绑定到引用数据模板的集合.
You can then bind your bing map to this collection referencing the data template.
<my:Map Margin="10,10,0,0"
Name="map1"
Center="39.95245, -75.163526"
ZoomLevel="11"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<my:MapItemsControl x:Name="MapPins"
ItemsSource="{Binding Pins}"
ItemTemplate="{StaticResource PinItemTemplate}"
/>
</my:Map>
然后你就可以正常绑定这个视图模型了.
You can then bind this view model as normal.
//Load map pins
MapViewModel view = new MapViewModel();
view.Load();
this.DataContext = view;
要在单击时处理图钉,您应该能够执行以下操作:
To process the pin when clicked you should be able to do the following:
private void Pushpin_MouseLeftButtonUp_1(object sender, MouseButtonEventArgs e)
{
Pushpin pin = (Pushpin)sender;
MessageBox.Show(pin.Content.ToString());
}
这篇关于在 Windows Phone 中将图钉绑定到 Bing 地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!