Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:41:51+00:00 2026-06-11T04:41:51+00:00

I am having a problem with my Listbox not updating/refresing.I have read here that

  • 0

I am having a problem with my Listbox not updating/refresing.I have read here that i need to use ObservableCollection but i didn’t have any luck.I am populating my Listbox from a XML.

 public class PestotoraPost
    {
        public string ID { get; set; }
        public string Date { get; set; }
        public string Name { get; set; }
        public string Message { get; set; }

    }
void WebLoad()
    {
        WebClient pestotora = new WebClient();
        pestotora.DownloadStringCompleted += new DownloadStringCompletedEventHandler(pestotora_DownloadStringCompleted);
        pestotora.DownloadStringAsync(new Uri("wwww.someURL.com/xml.php"));

    }

Note that the actual xml is a php containing the xml structure (from a sql DB)

 void pestotora_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        XElement doc = XElement.Parse(e.Result);
        listBox1.ItemsSource = from results in doc.Descendants("Data")
                            select new PestotoraPost
                            {
                                ID = results.Element("DataID").Value,
                                Date = results.Element("DataDate").Value,
                                Name=results.Element("DataName").Value,
                                Message=results.Element("DataMessage").Value     
                            };
    }

Everytime the XML changes,my Listbox won’t update doing a listBox1.UpdateLayout();

Any clue/help on how to start implementing this one?
Thank you very much.

UPDATED

namespace pestotora
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            UIload(true);
            WebLoad();

        }

        public ObservableCollection<PestotoraPost> Posts { get; set; }

        public class PestotoraPost
        {
            public string ID { get; set; }
            public string Date { get; set; }
            public string Name { get; set; }
            public string Message { get; set; }
        }


        void WebLoad()
        {

            WebClient pestotora = new WebClient();
            pestotora.DownloadStringCompleted += new DownloadStringCompletedEventHandler(pestotora_DownloadStringCompleted);
            pestotora.DownloadStringAsync(new Uri("www.domain.com/xml.php"));

        }

        void UIload(bool Splash)
        {
            if (Splash == true)
            {

                ApplicationBar.IsVisible = false;
            }
            else
            {

                ApplicationBar.IsVisible = true;
            }
        }

        void pestotora_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            //XDocument doc = XDocument.Parse(e.Result);

            XElement doc = XElement.Parse(e.Result);


            /* listBox1.ItemsSource = from results in doc.Descendants("Data")
                                select new PestotoraPost
                                {
                                    ID = results.Element("DataID").Value,
                                    Date = results.Element("DataDate").Value,
                                    Name=results.Element("DataName").Value,
                                    Message=results.Element("DataMessage").Value

                                }; */
            var list = from results in doc.Descendants("Data")
                       select new PestotoraPost
                       {
                           ID = results.Element("DataID").Value,
                           Date = results.Element("DataDate").Value,
                           Name = results.Element("DataName").Value,
                           Message = results.Element("DataMessage").Value
                       };
            Posts = new ObservableCollection<PestotoraPost>(list);
            foreach (var post in list)
            {
                Posts.Add(post);
            }

            UIload(false);


        }


        private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
        {
            //stckPost.Visibility = System.Windows.Visibility.Visible;

        }



        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Post.xaml", UriKind.Relative));
        }

        private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)
        {

            listBox1.UpdateLayout();
            //listBox1.ScrollIntoView(listBox1.Items[0]);

            WebLoad();
        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:41:52+00:00Added an answer on June 11, 2026 at 4:41 am

    1. If you use MVVM pattern: In viewModel implement INotifyPropertyChanged and declare:

    private ObservableCollection<PestotoraPost> _posts;
    public ObservableCollection<PestotoraPost> Posts 
    {
     get{return _posts;} 
     set
      {
         _posts = value;
         RaisePropertyChanged("Posts");
      }
     }
    

    in xaml write:

    <ListBox Name="listbox1" ItemsSource="{Binding Posts}"/>
    

    in pestotora_DownloadStringCompleted method:

    var list = from results in doc.Descendants("Data")
                                select new PestotoraPost
                                {
                                    ID = results.Element("DataID").Value,
                                    Date = results.Element("DataDate").Value,
                                    Name=results.Element("DataName").Value,
                                    Message=results.Element("DataMessage").Value     
                                };
    Posts = new ObservableCollection<PestotoraPosts>(list);
    

    2. If you run everything in a code-behind just declare

     public ObservableCollection<PestotoraPosts> Posts {get;set;}
    

    And in Page constructor init collection:

     Posts = new ObservableCollection<PestotoraPosts>();
    

    Xaml will have the same declaration.
    And in pestotora_DownloadStringCompleted method:

    var list = from results in doc.Descendants("Data")
                                select new PestotoraPost
                                {
                                    ID = results.Element("DataID").Value,
                                    Date = results.Element("DataDate").Value,
                                    Name=results.Element("DataName").Value,
                                    Message=results.Element("DataMessage").Value     
                                };
    foreach(var post in list)
    {
       Posts.Add(post);
    }
    

    What have we done?

    In xaml we set a databinding . Now listBox1 will get data from Post collection.
    Then we created new collection and notyfied listBox1 to update it’s view. (in first vatiant).

    In second variant we populated collection and as it was observable it notifyed a list box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with wpf listbox. my problem is that when I add
I'm having a problem styling my ListBox selection background. I used ListView originally, it
I am having a problem moving a treenode in a treeview to a listbox.
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
Im having problem in my UIscrollView ,this is what I have done: Whenever a
I'm having problem with datagrid view. I have attached an image with the code
I have a ListBox in a grid that gets databound when the page loads...
I have a form that has two buttons, textbox, listbox, and a combobox. The
I am having a problem with scrolling for my WPF application. Here is the
Im having a wierd problem with a WPF (+CaliburnMicro) listBox as defined below <GroupBox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.