views:

349

answers:

1

Hi,

I have a simple class that contains a string and an WPF Image control:

public class User
{
    public string Name { get; set; }

    public System.Windows.Controls.Image Image { get; set; }
}

Now I'm binding a list of instances of this class to a ListView.

What I would like to do now is make ListView display the Image property.

I've tried settings DisplayMemberPath to Image, but this shows the ToString value of image instead (System.Windows.Controls.Image).

How can I make it actually show the control?

Here's the XAML code:

<ListView Name="listView1" DisplayMemberPath="Image" />

Thanks!

A: 

You could create a DataTemplate that uses a ContentPresenter to display the image:

<ListBox>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <ContentPresenter Content="{Binding Image}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Aviad P.
Ah yes! That was what I was looking for :) Thanks!I did try using ListViewItem, but this somehow introduced weird behavior when selecting items.
Tijs Hendriks