Reputation: 13
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!
Upvotes: 1
Views: 5097
Reputation: 32680
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>
Upvotes: 2