图像列表绑定到一个列表框 [英] Binding a list of images to a ListBox
本文介绍了图像列表绑定到一个列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试着结合影像到列表框列表,但我得到的是型号名称列表
< ListBox的X:名称=PhotosListBox的ItemsSource ={结合MyImages}/>
该MyImages是名单,其中,BitMapImages>
现在,它只是返回一个列表 System.Windows.Media.Imaging.BitmapImage
而不是显示图像
编辑 如需进一步参考,这里是最后的code。
< ListBox的X:名称=PhotosListBox的ItemsSource ={结合MyImages}>
< ListBox.ItemTemplate>
<的DataTemplate>
<图像源={结合}拉伸=制服>< /图片>
< / DataTemplate中>
< /ListBox.ItemTemplate>
< /列表框>
解决方案
在默认情况下,绑定的数据类型的的ToString()
方法将被调用,它默认将返回完全限定的类型名称。
您应该定义一个定制的ItemTemplate ,在列表框。
Im trying to bind a list of images to a Listbox, but all I get is a list of Type names
<ListBox x:Name="PhotosListBox" ItemsSource="{Binding MyImages}" />
The MyImages is a List<BitMapImages>
Right now It just returns a list of System.Windows.Media.Imaging.BitmapImage
instead of showing the Images
EDIT For further ref, here is the final code.
<ListBox x:Name="PhotosListBox" ItemsSource="{Binding MyImages}" >
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding}" Stretch="Uniform"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
解决方案
By default, the ToString()
method of the bound data type will be invoked, which by default will return the fully qualified type name.
You should define a custom ItemTemplate for the ListBox.
这篇关于图像列表绑定到一个列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文