如何将自定义类(Ex:Student)对象的列表绑定到WPF中的列表视图? 我的XAML标记:ListView在这里。我想在Listview中显示用户,如html表
ListView Height="100" HorizontalAlignment="Left" Margin="27,98,0,0" Name="listView1" VerticalAlignment="Top" Width="320">
<ListView.View>
<GridView>
<GridViewColumn Width="160" Header="Name"></GridViewColumn>
<GridViewColumn Width="160" Header="Age"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
答案 0 :(得分:2)
有几件事:
将这两个应用于您的样本XAML:
<ListView Height="100" HorizontalAlignment="Left" Margin="27,98,0,0" Name="listView1" VerticalAlignment="Top" Width="320" ItemsSource="{Binding StudentCollection}">
<ListView.View>
<GridView>
<GridViewColumn Width="160" Header="Name" DisplayMemberBinding="{Binding Name}"></GridViewColumn>
<GridViewColumn Width="160" Header="Age" DisplayMemeberBinding="{Binding Age}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>