列表框导航到新页面并在windows phone 7应用程序的导航页面中详细显示数据

时间:2014-02-08 07:27:49

标签: c# windows-phone-7 listbox

我在windows phone 7应用程序中构建我的第一个应用程序。我有一些来自Web服务的数据,我在列表框中显示。我在列表框中显示的数据是News_Title,Date_Start,image。还有另一个数据News_Description,在单击列表框中的项目时,应与新页面中的数据先前数据一起显示。将有几个数据,所以我需要显示点击的数据。

我的cs文件,其中数据显示在webservice的列表框中:

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服务中的完整数据。请帮我解决这个问题。

我的新闻详情页面:

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 个答案:

答案 0 :(得分:1)

我看到了您的代码,您可以在listBox SelectionChanged方法中更改Navigate的代码:

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

并在导航页面上使用这三个参数。