
using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Navigation;

using System.Xml.Linq;

using Silverlight30.Model;

using System.Windows.Data;

namespace Silverlight30.Control

{

public partial class DataGrid : Page

{

public DataGrid()

{

InitializeComponent();

this.Loaded += new RoutedEventHandler(DataGrid_Loaded);

}

void DataGrid_Loaded( object sender, RoutedEventArgs e)

{

List<EmployeeModel> employees = new List<EmployeeModel>();

employees.Add( new EmployeeModel { Name = "aabb", DateOfBirth = DateTime.Now, Salary = 1111 });

employees.Add( new EmployeeModel { Name = "aabc", DateOfBirth = DateTime.Now, Salary = 1111 });

employees.Add( new EmployeeModel { Name = "abcc", DateOfBirth = DateTime.Now, Salary = 1122 });

employees.Add( new EmployeeModel { Name = "abbc", DateOfBirth = DateTime.Now, Salary = 1122 });

employees.Add( new EmployeeModel { Name = "aaab", DateOfBirth = DateTime.Now, Salary = 1122 });

employees.Add( new EmployeeModel { Name = "bcca", DateOfBirth = DateTime.Now, Salary = 1122 });

employees.Add( new EmployeeModel { Name = "bbac", DateOfBirth = DateTime.Now, Salary = 1133 });

employees.Add( new EmployeeModel { Name = "cbaa", DateOfBirth = DateTime.Now, Salary = 1133 });

employees.Add( new EmployeeModel { Name = "ccaa", DateOfBirth = DateTime.Now, Salary = 1133 });

employees.Add( new EmployeeModel { Name = "cccb", DateOfBirth = DateTime.Now, Salary = 1144 });

employees.Add( new EmployeeModel { Name = "cccc", DateOfBirth = DateTime.Now, Salary = 1155 });

employees.Add( new EmployeeModel { Name = "cabc", DateOfBirth = DateTime.Now, Salary = 1155 });

employees.Add( new EmployeeModel { Name = "cabb", DateOfBirth = DateTime.Now, Salary = 1166 });

// 通过 PagedCollectionView 的 GroupDescriptions 设置需要分组的字段,绑定到 DataGrid 后,DataGrid会自动对数据做分组显示

PagedCollectionView view = new PagedCollectionView(employees);

view.GroupDescriptions.Add( new PropertyGroupDescription( "Salary"));

dataGrid.ItemsSource = view;

}

}

}