简体   繁体   English

Windows Phone与Listbbx绑定列表框

[英]Windows Phone Bind Listbox With a Listbbx

I have a class with a list of images in it. 我有一堂课,上面有一张图片清单。

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

Hers the XAML 她的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>

The inner list box, ImageListBox, binds and shows the string value of the Uri. 内部列表框ImageListBox绑定并显示Uri的字符串值。 Im just not sure what to bind the image in the inner list box, image1, to? 我只是不确定将内部列表框中的图像image1绑定到什么?

Any help much appreciated. 任何帮助,不胜感激。

Regards Ross 问候罗斯

You are missing <ListBox.ItemTemplate> around your <DataTemplate> . 您缺少<DataTemplate>周围的<DataTemplate> <ListBox.ItemTemplate> <DataTemplate> This confuses ListBox, so it thinks it is actualy an item, not a template. 这使ListBox感到困惑,因此认为它实际上是项目,而不是模板。

Once you implement @Euphoric's resolution, bind the image1's source to ImageLocation. 实现@Euphoric的分辨率后,将image1的源绑定到ImageLocation。 Example: 例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM