bhaku
bhaku

Reputation: 448

listbox navigation to a new page and displaying data in details in the navigated page in windows phone 7 application

I am building my first app in windows phone 7 application. I have a few data coming from web service which i am displaying in a listbox. The data that i am displaying in the listbox is News_Title, Date_Start, image. There is another data News_Description which should be displayed along with the data previous data in a new page on clicking the item in the listbox. There will be several data so i need to display the data clicked.

My cs file where the data is displayed in listbox from the webservice is:

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

Now in news details page i want to display all the four data in details i.e complete data as in web service. Please help me to fix this issue.

My NewsDetails page:

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

Upvotes: 0

Views: 312

Answers (1)

Chris Shao
Chris Shao

Reputation: 8231

I see your code, and you can change your code of Navigate in listBox1_SelectionChanged method:

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

and use these three parameters on navigated page.

Upvotes: 1

Related Questions