views:

43

answers:

2

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.

+1  A: 

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

Muad'Dib
I changed Image to BitmapSource, but your answer was the closest, so i'll accept it.
INs
A: 

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.

Enough already