C# 如何在windows phone 7应用程序中收集从导航页传递的参数

C# 如何在windows phone 7应用程序中收集从导航页传递的参数,c#,windows-phone-7,C#,Windows Phone 7,我正在为WindowsPhone7构建一个应用程序,从webservice中提取列表框中的一些数据。现在,当用户单击列表框中的任何项目时,应该将其导航到另一个页面,其中必须显示有关所单击项目的详细信息。现在,我在导航上的编码中所做的如下所示: public class Newss { public string News_Title { get; set; } public string News_Description { get; set; }

我正在为WindowsPhone7构建一个应用程序,从webservice中提取列表框中的一些数据。现在,当用户单击列表框中的任何项目时,应该将其导航到另一个页面,其中必须显示有关所单击项目的详细信息。现在,我在导航上的编码中所做的如下所示:

    public class Newss
    {
        public string News_Title { get; set; }
        public string News_Description { get; set; }
        public string Date_Start { get; set; }
        public string image_path { get; set; }
        public BitmapImage ImageBind{get;set;}

      }

   public News()
    {
        InitializeComponent();

        KejriwalService.aapSoapClient client = new KejriwalService.aapSoapClient();
        client.getarvindNewsCompleted += new EventHandler<KejriwalService.getarvindNewsCompletedEventArgs>(client_getarvindNewsCompleted);
        client.getarvindNewsAsync();

        progressName.Visibility = System.Windows.Visibility.Visible;
    }

    void client_getarvindNewsCompleted(object sender, KejriwalService.getarvindNewsCompletedEventArgs e)
    {
        string result = e.Result.ToString();
        List<Newss> listData = new List<Newss>();
        XDocument doc = XDocument.Parse(result);

        progressName.Visibility = System.Windows.Visibility.Collapsed;

       foreach (var location in doc.Descendants("UserDetails"))

       {
           Newss data = new Newss();


            data.News_Title = location.Element("News_Title").Value;
            //data.News_Description = location.Element("News_Description").Value;
            data.Date_Start = location.Element("Date_Start").Value;
            data.image_path = location.Element("image_path").Value;
            data.ImageBind = new BitmapImage(new Uri( @"http://political-leader.vzons.com/ArvindKejriwal/images/uploaded/"+data.image_path, UriKind.Absolute));

            listData.Add(data);
        }

        listBox1.ItemsSource = listData;

    }

    private void Image_Back(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/AAP.xaml", UriKind.Relative));
    }

    private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        // If selected index is -1 (no selection) do nothing

        if (listBox1.SelectedIndex == -1)
            return;

        Newss news = listBox1.SelectedItem as Newss;

        NavigationService.Navigate(new Uri("/NewsDetails.xaml?News_Title=" + news.News_Title + "&News_Description=" + news.News_Description + "&image_path=" + news.image_path, UriKind.Relative));

        // Reset selected index to -1 (no selection)
        listBox1.SelectedIndex = -1;
    }
NewsDetails.xaml页面

 public NewsDetails()
    {
        InitializeComponent();

        var newsTitle        = NavigationContext.QueryString["News_Title"];
        var newsDescription  = NavigationContext.QueryString["News_Description"];
        var dateStart        = NavigationContext.QueryString["Date_Start"];
        var imagePath = NavigationContext.QueryString["image_path"];
     }

阅读本文,您可以使用NavigationContext.QueryString获取查询字符串参数。例如:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    var newsTitle = "";
    //check if particular parameter available in uri string
    if (this.NavigationContext.QueryString.ContainsKey("News_Title"))
    {
        //if it is available, get parameter value
        newsTitle = NavigationContext.QueryString["News_Title"];
    }
}
嗯,试试这个

在页面上,您正在提供参数:

NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=" + textBox1.Text, UriKind.Relative));`
在哪里收到:

受保护的覆盖无效OnNavigatedToSystem.Windows.Navigation.NavigationEventArgs e { 基于navigatedtoe


我知道如何导航,但这里我需要获取上一页到我导航的页面的值。我在导航到的页面中编写了您的代码,即NewsDetails.xaml,但我得到了一个为NullReference的异常。请查看我编写的代码,该代码提供了异常将其放入OnNavigatedTo事件而不是页面构造中ctor.NavigationContext.QueryString在调用构造函数时还不可用。如何显示图像。我只是在此处获取图像名称,而不是图像如果您曾在上一页中显示图像,请在此处使用相同的方法。您得到的当然应该是从上一页传递到图像lo的路径将图像控件放在UI中,并从该路径位置加载图像。
NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=" + textBox1.Text, UriKind.Relative));`
        string msg = "";



        if (NavigationContext.QueryString.TryGetValue("msg", out msg))

            textBlock1.Text = msg;


    }