Windows Phone “ListBox” ItemsSource

2019-06-11 05:44发布

I have a list and want to assign the downloaded feeds her. Also wanted to say that I am using the same code I've used in another app, but is giving an error as few as this. The other works perfectly. I will post few as the source of this. For if you can not 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: "Items collection 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 Have used this sample: http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f

0条回答
登录 后发表回答