3 Replies - 1587 Views - Last Post: 11 December 2012 - 07:44 AM Rate Topic: -----

#1 wolne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 28-June 12

How do you place information from an xml file into a listbox?

Posted 10 December 2012 - 07:30 PM

Here is what I have. I would expect the xml file to appear in the listbox after the user selects a term. However the screen just goes blank. Any ideas?

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml;

namespace PhoneApp5
{
    public partial class MainPage : PhoneApplicationPage
    {
        public class Item
        {
            public string ItemLine1 { get; set; }
            public string ItemLine2 { get; set; }
        }

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            
            PageTitle.Text = "Terms";
            List<Item> list = new List<Item>();
            Item item = new Item();
            item.ItemLine1 = "Third Summer 2013";
            item.ItemLine2 = "Classes";
            list.Add(item);
            item = new Item();
            item.ItemLine1 = "Second Summer 2013";
            item.ItemLine2 = "Classes";
            list.Add(item);
            item = new Item();
            item.ItemLine1 = "First Summer 2013";
            item.ItemLine2 = "Classes";
            list.Add(item);
            item = new Item();
            item.ItemLine1 = "Spring 2013";
            item.ItemLine2 = "classes";
            list.Add(item);
            item = new Item();
            item.ItemLine1 = "Fall 2012";
            item.ItemLine2 = "Classes";
            list.Add(item);
            
            Dispatcher.BeginInvoke(new Action(() => ListBox1.ItemsSource = list));

        }

        void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
           ApplicationTitle.Text = e.Result;
        }

        private void ListBox1_Selectionchanged(object sender, SelectionchangedEventArgs e)
        {
            //if (sender != null) PageTitle.Text = sender.ToString();
            //if (e != null) PageTitle.Text = e.AddedItems.Count.ToString();

            //IEnumerator ie = e.AddedItems.GetEnumerator();
            //ie.MoveNext();
            //if (e != null) ApplicationTitle.Text = ie.Current.ToString();

             WebClient wc = new WebClient();
             wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
             wc.DownloadStringAsync(new Uri("http://www.usi.edu/webservices/iphone/USIINFO201310.xml"));
             
             
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: How do you place information from an xml file into a listbox?

#2 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 314
  • View blog
  • Posts: 490
  • Joined: 13-June 12

Re: How do you place information from an xml file into a listbox?

Posted 11 December 2012 - 01:28 AM

You have downloaded the string (XML file) then your wc_DownloadStringComplete event handler changes your application title text. You're doing nothing to assign it to the listbox.
Was This Post Helpful? 1
  • +
  • -

#3 wolne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 28-June 12

Re: How do you place information from an xml file into a listbox?

Posted 11 December 2012 - 04:50 AM

View PostMrShoes, on 11 December 2012 - 01:28 AM, said:

You have downloaded the string (XML file) then your wc_DownloadStringComplete event handler changes your application title text. You're doing nothing to assign it to the listbox.



Even if I change it to listbox in that event, it still doesn't work.
Was This Post Helpful? 0
  • +
  • -

#4 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 314
  • View blog
  • Posts: 490
  • Joined: 13-June 12

Re: How do you place information from an xml file into a listbox?

Posted 11 December 2012 - 07:44 AM

You have a string, which holds XML. What you want is to deserialize an XML document to your classes. The list you create by deserializing can then be added to your listbox.

I seem to remember this tutorial being a good one.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1