C# 使用图钉和对象将参数从一页传递到另一页
我正在为WindowsPhone7构建一个应用程序,我需要在地图上打印图钉,所以我已经完成了。我从数据库响应中读取数据 问题是…每个图钉都意味着一个位置,但我不知道如何将该位置添加到图钉或将业务属性发送到另一个页面,在那里我将在一些文本块中记录它们C# 使用图钉和对象将参数从一页传递到另一页,c#,silverlight,windows-phone-7,bing-maps,pushpin,C#,Silverlight,Windows Phone 7,Bing Maps,Pushpin,我正在为WindowsPhone7构建一个应用程序,我需要在地图上打印图钉,所以我已经完成了。我从数据库响应中读取数据 问题是…每个图钉都意味着一个位置,但我不知道如何将该位置添加到图钉或将业务属性发送到另一个页面,在那里我将在一些文本块中记录它们 void app_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { Place business = new Place(
void app_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Place business = new Place();
if (e.Error == null)
{
XDocument feedXml = XDocument.Parse(e.Result);
foreach (var properties in feedXml.Descendants("RESULT"))
{
Pushpin p = new Pushpin();
p.Location = new GeoCoordinate((double)properties.Element("LATITUDE"), (double)properties.Element("LONGITUDE"));
p.Content = properties.Element("NAME").Value;
p.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(pushPin_Tap);
p.DoubleTap += new EventHandler<System.Windows.Input.GestureEventArgs>(pushPin_DoubleTap);
business.Id = (int)properties.Element("ID");
business.Category = properties.Element("CATEGORY").Value;
business.Name = properties.Element("NAME").Value;
business.Street = properties.Element("STREET").Value;
business.City = properties.Element("CITY").Value;
business.Neighborhood = properties.Element("NEIGHBORHOOD").Value;
business.State = properties.Element("STATE").Value;
business.ZipCode = properties.Element("ZIPCODE").Value;
business.Country = properties.Element("COUNTRY").Value;
business.Hours = properties.Element("HOURS").Value;
business.Description = properties.Element("DESCRIPTION").Value;
business.Images = properties.Element("IMAGES").Value;
business.Latitude = (double)properties.Element("LATITUDE");
business.Longitude = (double)properties.Element("LONGITUDE");
business.Payment = "Nope";
business.Distance = properties.Element("DISTANCE").Value;
map1.Children.Add(p);
}
}
}
有什么帮助或建议吗?谢谢:您可以使用PhoneApplicationService.Current.State在页面之间存储和检索数据。例如,在A页中:
Place loc = new Place();
//fill the Place properties
PhoneApplicationService.Current.State["place"]=loc;
//Navigate to Page B
在OnNavigatedTo内的B页中:
Place place = PhoneApplicationService.Current.State["place"];
var obj = App.Current as App;
aPlace = obj.place; //assuming you have aPlace declared before
您可能希望在其中添加一些异常捕获,并确保状态集合中存在键pin
Yo还可以使用App.xaml.cs中的公共属性
public Place place {get;set;}
在A页:
var obj = App.Current as App;
obj.place = aPlace; //assumming aPlace is already created
在第B页中,导航到:
Place place = PhoneApplicationService.Current.State["place"];
var obj = App.Current as App;
aPlace = obj.place; //assuming you have aPlace declared before