2014-03-04 118 views
0

我有一個問題,從我的提要中獲取RSS圖像以顯示在我的列表框中使用綁定。Windows Phone在綁定的列表框中顯示RSS圖像

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> 

這裏是代碼來獲取圖像:

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; 


     }); 

    } 

和存儲/檢索圖像類:

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; } 
} 

我認爲它的綁定我做錯了,我希望有人能夠幫助我。謝謝。

+0

圖像的源設置爲源=「{結合了feeddata}」,而不是網址? –

+0

我已經解決了這個問題,但是謝謝。 – Thunder

+0

請將您的解決方案作爲答案@Thunder發佈! :) –

回答

0

我發現通過改變溶液我結合這一點:

Binding Links[1].Uri 
相關問題