0

I have a problem with a RSS feed app. When my app launches, the listbox gets the feeds and show them in my listbox, but when i press my refresh button the listbox never updates, it just show the same items again, but if i close the app, and then relaunch it, it will show the latest feeds. I hope there is someone that can help. Thanks.

MainWindow.xaml:

<ListBox Grid.Row="1" Name="feedListBox" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="feedListBox_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            ...
                            ...
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

MainWindow.cs:

private void appBarRefresh_Click(object sender, EventArgs e)
    {
        feedListBox.ItemsSource = null;

        GetFeed(IsolatedStorageSettings.ApplicationSettings["key"].ToString());
    }

private void GetFeed(string rss)
    {
        WebClient webClient = new WebClient();

        webClient.DownloadStringAsync(new System.Uri(rss));
        webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
    }

private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        if (e.Error != null)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                MessageBox.Show(e.Error.Message);
            });
        }
        else
        {
            this.State["feed"] = null;
            this.State.Clear();
            this.State["feed"] = e.Result;

            UpdateFeedList(e.Result);
        }
    }

private void UpdateFeedList(string feedXML)
    {
        StringReader stringReader = new StringReader(feedXML);
        XmlReader xmlReader = XmlReader.Create(stringReader);
        SyndicationFeed feed = SyndicationFeed.Load(xmlReader);

        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            feedListBox.ItemsSource = feed.Items;
        });
        ;
    }
Kara
  • 6,115
  • 16
  • 50
  • 57
Thunder
  • 117
  • 18

2 Answers2

1

Try this in UpdateFeedList(string feedXML)

feedListBox.ItemsSource = null;
feedListBox.ItemsSource = feed.Items;
bit
  • 4,407
  • 1
  • 28
  • 50
0

Is your list implementing INotifyCollectionChanged? If it's not an ObservableCollection, then changes to it's contents will not automatically be reflected in the UI.

More info at the following thread

Community
  • 1
  • 1
Krekkon
  • 1,349
  • 14
  • 35