我试图将图像列表绑定(bind)到列表框,但我得到的只是类型名称列表
<ListBox x:Name="PhotosListBox" ItemsSource="{Binding MyImages}" />
MyImages 是 List<BitMapImages>
现在它只返回 System.Windows.Media.Imaging.BitmapImage
的列表而不是显示图像
编辑 为了进一步引用,这里是最终代码。
<ListBox x:Name="PhotosListBox" ItemsSource="{Binding MyImages}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Stretch="Uniform"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
最佳答案
默认情况下,将调用绑定(bind)数据类型的 ToString()
方法,该方法默认返回完全限定的类型名称。
您应该定义一个自定义 ItemTemplate对于列表框。
关于c# - 将图像列表绑定(bind)到 ListBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6650922/