0

简单的问题,但我完全糊涂了。我正在使用 C# 开发一个 wp7 应用程序。我想要一个列表框,其中输入的图像项编号应该相同,即列表框应包含“n”图像控件,其中源设置为单个图像,其中“n”是用户输入的列表框项的编号。例如,如果用户输入'10',那么列表框应该有十个项目。我希望列表框 ItemsPanelTemplate 作为 Wrap-panel。有人可以建议我如何得到这个吗?

4

1 回答 1

2

在您的 XAML 中定义一个类似这样的 ListBox

<ListBox x:Name="ListBoxImages">
    <ListBox.ItemTemplate>
        <DataTemplate>
           <StackPanel>
              <Image Source="{Binding Imagesource}" Width="300"/>
           </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

然后像这样在后面的代码中设置它的Source

int noOfImages = 10; //Take the input from user
List<ImageClass> imageList = new List<ImageClass>();
for(int i=0; i<noOfImages; i++)
imageList.Add(new ImageClass() { Imagesource = "/user.jpg" });

ListBoxImages.ItemsSource = imageList; //Set the source of the listbox here

ImageClass 在哪里,

public class ImageClass
{
    public String Imagesource { get; set; }
}

以上是供您理解的示例。请明智地定制以满足您的需求

于 2012-09-27T10:52:48.167 回答