Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF列表视图显示图像_Wpf_Image_Listview_Controls_Bind - Fatal编程技术网

WPF列表视图显示图像

WPF列表视图显示图像,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

我有一个简单的类,它包含一个字符串和一个WPF
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>