WPF 中的listview 怎样绑定结构体数组?

我定义的一个结构体数组,结构体里有三个属性,怎样把这个结构体数组三个属性的数据相应的显示在一个listview里?... 我定义的一个结构体数组,结构体里有三个属性,怎样把这个结构体数组三个属性的数据相应的显示在一个listview 里? 展开
 我来答
匿名用户
2015-10-17
展开全部
//定义数据结构
class Student
{
    public int Id { get; set; }
    public string Name { get; set; }
    public DateTime Birth { get; set; }
}
//定义ListView 视图结构
<ListView x:Name="livStudent">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path=Id}" />
            <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" />
            <GridViewColumn Header="Birth" DisplayMemberBinding="{Binding Path=Birth}" />
        </GridView>
    </ListView.View>
</ListView>
//构造数据源
var students = new Student[2];
students[0] = new Student() { Id = 1, Name = "a", Birth = new DateTime(2015, 1, 1) };
students[1] = new Student() { Id = 2, Name = "b", Birth = new DateTime(2015, 2, 1)};
//绑定数据
livStudent.ItemsSource = students;


DisplayMemberBinding="{Binding Path=Id}"

设置绑定的属性名称, 注意:是属性。

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式