Connect to XML file at web address for WP7 app

前端 未结 2 1985
感情败类
感情败类 2021-01-28 03:16

I\'ve been trying to learn the ins-and-outs of Windows Phone 7 programming over the past few weeks. I have learned most of the basics but I\'ve been having trouble finding a tut

2条回答
  •  囚心锁ツ
    2021-01-28 03:54

    UPDATE:

    I think you were right that the problem may be when I call GetRoster. This is the context in which I'm calling it:

    '

    namespace TwitterMix
    {
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
        }
    
    
        private void GetRoster()
        {
            WebClient rstr = new WebClient();
    
            rstr.DownloadStringCompleted += new DownloadStringCompletedEventHandler(roster_DownloadStringCompleted);
            rstr.DownloadStringAsync(new Uri("http://www.danfess.com/data.xml"));
        }
    

    '

    What would be the correct place in which to call it? By the way I'm sorry about the code sections not appearing correctly.


    Hey guys! Thanks for the help! I didn't create an account earlier so this is probably going to show up as an answer since I'm on a different computer. I did my best in changing that Twitter Tutorial into what I am trying to do. I'm getting no errors but it's not showing any content within the emulator. I created an XML file and uploaded it to my personal website. Unfortunately, I cannot get the code sample button to work even remotely well. So I'm sorry this looks so poorly. The XML file contained this info:

    
    
      Blake25
      Jane29
      Bryce29
      Colin29
    
    

    Here is MainPage.xaml.cs:

    private void GetRoster()
        {
            WebClient rstr = new WebClient();
    
            rstr.DownloadStringCompleted += new DownloadStringCompletedEventHandler(roster_DownloadStringCompleted);
            rstr.DownloadStringAsync(new Uri("http://www.MyPersonalWebsiteURL.com/data.xml"));
        }
    
        void roster_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
                return;
    
            XElement xmlPersons = XElement.Parse(e.Result);
    
            var list = new List();
    
            foreach (XElement person in xmlPersons.Elements("person"))
            {
                var name = person.Element("name").Value;
                var age = person.Element("age").Value;
    
    
                list.Add(new RosterViewModel
                {
                    Name = name,
                    Age = age,
                 });
            }
    
            rosterList.ItemsSource = list;
        }
    
    
        public class RosterViewModel
        {
            public string Name { get; set; }
            public string Age { get; set; }
        }
    }
    

    Now MainPage.xaml:

    '

    
    
        
            
            
        
    
        
        
            
            
        
    
        
        
            
                
                    
                        
    
                            
                                
                                
                            
                        
                    
                
            
        
    
    

    '

    However! When I run the app in the emulator I receive no errors, but no content is displayed whatsoever. I know the solution is probably very simple so I'd like to reiterate how much your help means to me. Thanks very much for any advice you can provide.

提交回复
热议问题