(13) WPF 数据显示
一、DataGrid
二、ListView
ListView继承自ListBox
<ListView Margin="5" Name="listView"> <ListView.View> <GridView> <GridView.Columns> <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Path=Id}" Width="60"></GridViewColumn> <GridViewColumn Header="Age" DisplayMemberBinding="{Binding Path=Age}"></GridViewColumn> <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"></GridViewColumn> </GridView.Columns> </GridView> </ListView.View> </ListView>
public partial class MainWindow : Window { Student student1; Student student2; Student student3; List<Student> list = new List<Student>(); public MainWindow() { InitializeComponent(); student1 = new Student(1, 15, "Tom"); student2 = new Student(2, 17, "Maiko"); student3 = new Student(3, 13, "Kate"); list.Add(student1); list.Add(student2); list.Add(student3); listView.ItemsSource = list; } } class Student { private int id; private int age; private string name; public Student(int id, int age, string name) { this.id = id; this.age = age; this.name = name; } public int Id { get => id; set => id = value; } public int Age { get => age; set => age = value; } public string Name { get => name; set => name = value; } }
三、TreeView