2014-02-08 87 views
0

我在windows phone 7应用程序中构建我的第一个应用程序。我有一些数据来自web服务,我在列表框中显示。我在列表框中显示的数据是News_Title,Date_Start,图像。在单击列表框中的项目时,还应该在新页面中显示另一个数据News_Description以及数据以前的数据。会有几个数据,所以我需要显示点击的数据。listbox导航到新页面并在windows phone 7应用程序的导航页面中显示详细数据

我的CS文件,其中的数据是从Web服务显示在列表框中为:

public partial class News : PhoneApplicationPage 
{ 
    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; 

     // Navigate to the new page 
     NavigationService.Navigate(new Uri("/NewsDetails.xaml?selectedItem=" + listBox1.SelectedIndex, UriKind.Relative)); 

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

现在在新闻详情页我想显示所有细节四个数据即完整的数据,如Web服务。请帮我解决这个问题。

我NewsDetails页:

namespace KejriwalPhoneApp 
{ 
    public partial class NewsDetails : PhoneApplicationPage 
    { 
     public NewsDetails() 
     { 
      InitializeComponent(); 
     } 

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

回答

1

我看到你的代码,你可以改变你浏览的代码listBox1_SelectionChanged方法:

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

和导航页上使用这三个参数。

+0

请参阅我现在编辑的代码。我需要在哪里发送参数? – bhaku

+1

是的,你需要在导航时发送参数。导航页面也需要做。如:var param1 = NavigationContext.QueryString [“ParamName”];在OnNavigatedTo方法中。 –