Click here to Skip to main content
15,909,498 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

C#
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"));
             
             
        }
    }
Posted
Updated 10-Dec-12 15:30pm
v2

1 solution

have you tried debugging your application ?

In your case at the end of MainPage constructor you are filling your list box which eventually makes call to ListBox1_SelectionChanged method and the reason for the screen blank may be because of the operation performed side SelectionChanged method.

double check wc.DownloadStringAsync doesnt blank your page.

it's worth to note that
ListBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) 
method gets called when ever you try to add a new item to the list or you change the item selection.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900