WPF ListView show Image
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 开发者_如何学Goinstead (System.Windows.Controls.Image
).
How can I make it actually show the control?
Here's the XAML code:
<ListView Name="listView1" DisplayMemberPath="Image" />
Thanks!
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>
精彩评论