How to display array of images in Silverlight ComboBox?
I have array of objects with created images 开发者_如何转开发(Object.Image), i want to show images in combobox.
<ComboBox x:Name="typeSelection" ItemsSource="..." DisplayMemberPath="Image"></ComboBox>
Combobox shows Image.ToString(), not image itself, how to fix it.
You need to set the ItemTemplate for the combobox. something like this.... (this is for an array of paths to the images, not actual images)
<ComboBox>
<ComboBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding MySourcePath}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
here is a nice example of comboboxes in silverlight
The default implementation of a ComboBox is to use the ItemSource as the source of a list of items and the DisplayMemberPath as the name of a property to use for a TextBlock.Text value. Therefore it looks at your "Image" property and does a .ToString() to convert it for the TextBlocks in the list.
Instead you need to implement a ComboBoxItem Control Template, to describe the elements in each displayed item (text, images, whatever). Those controls will themselves contain bindings to the properties on your objects. e.g:
<Image Source={Binding Image}/>
As Muad'Dib pointed out (30 seconds earlier), the Image must be a string that is the path of the image, not an actual image object.
精彩评论