Question

i have a problem getting RSS images from my feed to show up inside my listbox using binding.

MainWindow.xaml:

<ListBox Grid.Row="1" Name="feedListBox" ScrollViewer.VerticalScrollBarVisibility="Auto" SelectionChanged="feedListBox_SelectionChanged">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Border 
                    Width="110" Height="110">
                                    <Image Source="{Binding FeedData}" Stretch="UniformToFill"
                       AutomationProperties.Name="{Binding Title}"/>
                                </Border>
                                <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,0,0,0">
                                    <TextBlock TextDecorations="Underline" Foreground="Green" FontSize="24" Name="feedTitle" TextWrapping="Wrap" Margin="12,0,0,0" Text="{Binding Title.Text, Converter={StaticResource RssTextTrimmer}}" />
                                    <TextBlock Name="feedSummary" TextWrapping="Wrap" Margin="12,0,0,0" Text="{Binding Summary.Text, Converter={StaticResource RssTextTrimmer}}"/>
                                    <TextBlock Name="feedPubDate" Foreground="DarkGray" Margin="12,0,0,10" Text="{Binding PublishDate, StringFormat='{}{0:dd/MM/yyyy HH:mm:ss}'}" />
                                </StackPanel>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

and here is the code to get the images:

MainWindow.cs:

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

        foreach (SyndicationItem item in feed.Items)
        {

            foreach (SyndicationLink enclosure in item.Links.Where<SyndicationLink>(x => x.RelationshipType == "enclosure"))
            {
                Uri url = enclosure.Uri;
                long length = enclosure.Length;
                string mediaType = enclosure.MediaType;
                feedItem.Image = url;
            }
        }

        Deployment.Current.Dispatcher.BeginInvoke(() =>
        {

            feedListBox.ItemsSource = feed.Items;


        });

    }

and the classes to store/retrieve the images:

public class FeedData
{
    private List<FeedItem> _Items = new List<FeedItem>();
    public List<FeedItem> Items
    {
        get
        {
            return this._Items;
        }
    }
}

public class FeedItem
{
    //public string Title { get; set; }
    //public string Content { get; set; }
    //public DateTime PubDate { get; set; }
    //public Uri Link { get; set; }
    public Uri Image { get; set; }
}

I think its the binding im doing wrong, i hope there is someone that can help me. Thanks.

Was it helpful?

Solution

I found the solution by changing my binding to this:

Binding Links[1].Uri
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top