2012-04-28 77 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>