1

Windows Phone 7用のアプリケーションを作成していますが、地図に画鋲を印刷する必要があるので、それを実行しました。データベースの応答からデータを読み取りました。

問題は...すべての画鋲は場所を意味しますが、場所を画鋲に追加する方法や、ビジネスプロパティを別のページに送信する方法がわかりません。そこで、いくつかのテキストブロックにそれらを書き留めます。

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


            }
        }
    }

次に、このメソッドを使用していくつかのパラメーターを他のページに送信しますが、必要なビジネスではなく、画鋲の値を送信します。

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


    }

ヘルプや推奨事項はありますか?ありがとう :)

4

1 に答える 1

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"];

そこにいくつかの例外キャッチを追加し、キー「ピン」がStateコレクションに存在することを確認することをお勧めします。

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で、OnNavigatedTo:

var obj = App.Current as App;
aPlace = obj.place; //assuming you have aPlace declared before
于 2012-11-28T00:05:06.593 に答える