2012-04-28 80 views
0

我有一個包含圖像列表的類。Windows Phone綁定列表框Listbbx

public class RSSClass 
{ 
public string Title { get; set; } 
public string Summary { get; set; } 
public string PubDate { get; set; } 
public List<ImageData> ImagePath { get; set; } 

public class ImageData 
{ 
    public Uri ImageLocation 
    { 
     get; 
     set; 
    } 
} 
} 

赫斯的XAML

  <ListBox Name="lstRSS"> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <StackPanel> 
          <StackPanel.Resources> 
          </StackPanel.Resources> 
          <TextBlock Text="{Binding Path=Title}"> </TextBlock> 
          <TextBlock Text="{Binding Path=PubDate}"></TextBlock> 
          <TextBlock Text="{Binding Path=Summary}"></TextBlock> 
          <ListBox x:Name="ImageListBox" ItemsSource="{Binding ImagePath}"> 
            <DataTemplate> 
             <Image x:Name="image1" Source="{Binding}" MaxHeight="80" MaxWidth="120" Margin="0"></Image> 
            </DataTemplate> 
          </ListBox> 
         </StackPanel> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 

內部列表框,ImageListBox,結合並示出了URI的字符串值。我只是不知道如何綁定內部列表框image1中的圖像?

任何幫助非常感謝。

問候 羅斯

+0

您是否試過Source =「{Binding ImageLocation}」? – 2012-04-28 16:21:24

+0

試過這個隊友,沒有運氣,謝謝你的建議! – user746585 2012-04-28 16:34:17

+0

您是否嘗試過使用字符串作爲ImageLocation而不是Uri? – 2012-04-28 17:08:49

回答

1

你缺少你<ListBox.ItemTemplate>圍繞<DataTemplate>。這混淆了ListBox,所以它認爲它實際上是一個項目,而不是一個模板。

+0

這就是建議欣快。當我添加建議的ItemTemplate時,我得到了某種綁定,ListBox包含了一些「RSSClass + ImageData」字符串。當我刪除它時,沒有任何東西被渲染。因此,它看起來像列表框綁定到對象,而不是圖像 – user746585 2012-04-28 23:09:38

+0

你是否正確地添加了它?當你沒有指定DataTemplate時,你所描述的會發生,因此它會綁定到對象的ToString。 – Euphoric 2012-04-29 19:47:34

0

實施@ Euphoric的解析後,將image1的源代碼綁定到ImageLocation。例如:

<Image x:Name="image1" Source="{Binding ImageLocation}" MaxHeight="80" MaxWidth="120" Margin="0"></Image>