Original address: http://blog.csdn.net/wangweiandsuo/article/details/8500864
Mainly write some recent time to learn about WPF display
The direct display is somewhat similar to the GridView in. NET, which can be displayed by simply throwing a list into the DataGrid and automatically loading the object's properties onto the page.
MainWindow.xaml.cs[HTML] View plain copy Public mainwindow () { initializecomponent (); } Private void window_loaded (object sender, routedeventargs e) { List<user> list = new list<user> (); for (int i = 0; i < 10; i++) { user u = new user ( ); u.id = i + 1; u.Name = "AA" + i; list. ADD (u); } this.grid_user. itemssource = list; } } public class User { public int Id { get; set; } &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;PUBLIC&NBSP;STRING&NBSP;NAME&NBSP;{&NBSP;GET;&NBSP;SET;&NBSP;} }
MainWindow.xaml alternationcount= "2" Interlaced color[HTML] View Plain copy <Grid> <datagrid name= "Grid_user" isreadonly= "True" alternationcount= "2" > <DataGrid.Columns> <DataGridTextColumn Header= "Id" width= " binding=" {binding id} "/> <datagridtextcolumn header= "Name" width= " binding=" "{binding name}"/> </DataGrid.Columns> </DataGrid> </Grid>
Customize the style of the DataGrid [HTML] View plain copy <resourcedictionary