Windows Phone "ListBox" ItemsSource

I have a list and want to assign downloaded channels to it. I also wanted to say that I am using the same code that I used in another application, but that it makes a mistake. The other works fine. I'll tell you a little about the source of this. For if you cannot stay too long.

    private void carregaListas()
            {           
                WebClient webClient = new WebClient();
                webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
                webClient.DownloadStringAsync(new System.Uri("http://www.news-medical.net/syndication.axd?format=rss"));
    }


private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    stkLife.Visibility = Visibility.Visible;
                    stbOfLife.Begin();
                });
            }
            else
            {
                // Save the feed into the State property in case the application is tombstoned.
                //gridProgressBar.Visibility = Visibility.Collapsed;
                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;                
            });
        }

      

Error: "Collection item must be empty before using ItemsSource.

XAML code:

<ListBox x:Name="feedListBox" Margin="0,0,-12,0" SelectionChanged="feedListBox_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0,0,0,17">
                                <StackPanel.Background>
                                    <SolidColorBrush Color="#FFC5C5C5" Opacity="0.35"/>
                                </StackPanel.Background>
                                <TextBlock Text="{Binding Title.Text, Converter={StaticResource RssTextTrimmer}}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" Foreground="White" FontSize="30"/>
                                <TextBlock Text="{Binding Summary.Text, Converter={StaticResource RssTextTrimmer}}" TextWrapping="Wrap" Style="{StaticResource PhoneTextSubtleStyle}" Foreground="#99FFFFFF"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>

      

I used this sample: http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f

0


source to share





All Articles