Binding a list of images to a ListBox
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>开发者_Go百科;
</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.
You need to use an ItemTemplate
other than the default so that the ListBox
knows how to handle the data type being passed to it.
See: http://msdn.microsoft.com/en-us/library/ms742521.aspx
精彩评论