1

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!

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Ah yes! That was what I was looking for :) Thanks! I did try using ListViewItem, but this somehow introduced weird behavior when selecting items.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.