将信息从xml文件放入列表框

时间:2012-12-11 02:38:13

标签: c#

这就是我所拥有的。我希望在用户选择一个术语后,xml文件会出现在列表框中。然而,屏幕只是空白。我有另一个xml文件,与我的代码完全一致,但我需要它来为这个xml文件工作。它非常大,所以我想也许这可能是它不起作用的原因。有什么想法吗?

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


    }
}
}

0 个答案:

没有答案