2012-11-27 17 views
1

我正在爲Windows Phone 7創建應用程序,我需要在地圖中打印圖釘,所以我已經完成了這項工作。我從數據庫響應中讀取數據。將參數從一個頁面傳遞到另一個頁面使用圖釘和對象

問題是......每個圖釘意味着一個地方,但我不知道如何添加到圖釘的位置或發送業務屬性到另一個頁面,我要在哪裏寫下它們的TextBlocks。

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); 


      } 
     } 
    } 

然後,我使用的方法的一些參數發送到其他頁面,但圖釘值,而不是busineess,我需要..

void pushPin_DoubleTap(object sender, System.Windows.Input.GestureEventArgs e) 
    { 
     e.Handled = true; 


     var businessinfo = ((FrameworkElement) sender).Tag as Place; 

     /*if (businessinfo != null) 
     { 
      string name = businessinfo.Name; 
      string category = businessinfo.Category; 
      string address = businessinfo.Street; 
      string distance = businessinfo.Distance; 
      string payment = businessinfo.Payment; 
      string hours = businessinfo.Hours; 

      NavigationService.Navigate(new Uri(
      "/BusinessInfoPage.xaml?name=" + name + 
      "&category=" + category + 
      "&address=" + address + 
      "&distance=" + distance + 
      "&payment=" + payment + 
      "&hours=" + hours, UriKind.Relative)); 

     } 
     */ 

     NavigationService.Navigate(new Uri("/BusinessInfoPage.xaml?name=Oxxo&category=Convenience&address=Somewhere&distance=.005km&payment=Nothing&hours=8am to 9pm", UriKind.Relative)); 


    } 

任何幫助或建議?謝謝:)

回答

0

您可以使用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"]; 

您可能需要添加一些異常捕獲在那裏,並確保關鍵「銷」的一國收集。

呦也可以在App.xaml.cs中使用公共屬性。

public Place place {get;set;} 

在網頁A:

var obj = App.Current as App; 
obj.place = aPlace; //assumming aPlace is already created 

在網頁B,的OnNavigatedTo:

var obj = App.Current as App; 
aPlace = obj.place; //assuming you have aPlace declared before 
相關問題