WPF列表视图显示图像
我有一个简单的类,它包含一个字符串和一个WPFWPF列表视图显示图像,wpf,image,listview,controls,bind,Wpf,Image,Listview,Controls,Bind,我有一个简单的类,它包含一个字符串和一个WPFImage控件: public class User { public string Name { get; set; } public System.Windows.Controls.Image Image { get; set; } } 现在,我将这个类的实例列表绑定到一个ListView 我现在要做的是使ListView显示图像属性 我尝试将设置displaymberpath设置为Image,但这显示的是Image的ToSt
Image
控件:
public class User
{
public string Name { get; set; }
public System.Windows.Controls.Image Image { get; set; }
}
现在,我将这个类的实例列表绑定到一个ListView
我现在要做的是使ListView
显示图像属性
我尝试将设置displaymberpath
设置为Image,但这显示的是Image的ToString
值(System.Windows.Controls.Image
)
我如何使它实际显示控件
以下是XAML代码:
谢谢 您可以创建一个
DataTemplate
,该模板使用ContentPresenter
来显示图像:
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Image}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
啊,是的!这就是我想要的:)谢谢!我确实尝试过使用ListViewItem,但这在选择项目时引入了奇怪的行为。
<ListBox>
<ListBox.ItemTemplate>
<DataTemplate>
<ContentPresenter Content="{Binding Image}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>