1 新建一个silverlight应用程序
2 新建一个Students的类
类里面定义数据类型
代码如下
public class Student { public string Name { get; set; } public string Phone { get; set; } public string Address { get; set; } } }
3 在xaml.cs后代代码里面装载数据
如下
public void LoadDate() { students = new Student[] { new Student{Name = "1", Phone = "1", Address = "1"}, new Student{Name = "2", Phone = "2", Address = "2"}, new Student{Name = "3", Phone = "3", Address = "3"}, new Student{Name = "4", Phone = "4", Address = "4"} }; }
4拖一个dataGrid的控件到界面上
修改AutoGenerateColumns="true"
5
Student[] students; public MainPage() { InitializeComponent(); LoadDate(); dataGrid1.ItemsSource = students; }
6 效果图