public void BindFaultGridInfo(IList<HealthStatusApp.Web.Models.FaultMajorModel> list) { rg_Fault.Columns.Clear(); var DefferList = list.GroupBy(m => m.BurdenMajor).ToList(); IList<HealthStatusApp.Web.Models.FaultMajorModel> itemFaultlist = DefferList[0].OrderBy(m => m.TimeStamp).ToList(); for (int i = 0; i < itemFaultlist.Count; i++) { if (i == 0) { Telerik.Windows.Controls.GridViewColumn mColumn = new Telerik.Windows.Controls.GridViewColumn(); mColumn.Header = "责任专业"; mColumn.HeaderTextAlignment = TextAlignment.Center; //动态添加一列数据模板 StringBuilder mbTemp = new StringBuilder(); mbTemp.Append("<DataTemplate "); mbTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' "); mbTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' "); mbTemp.Append("xmlns:d='http://schemas.microsoft.com/expression/blend/2008' "); mbTemp.Append("xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' "); mbTemp.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' >"); mbTemp.Append("<TextBlock Text=\"{Binding BurdenMajor}\"/>"); mbTemp.Append("</DataTemplate>"); DataTemplate dtmTemplate = (DataTemplate)XamlReader.Load(mbTemp.ToString()); mColumn.CellTemplate = dtmTemplate; rg_Fault.Columns.Add(mColumn); } Telerik.Windows.Controls.GridViewColumn oColumn = new Telerik.Windows.Controls.GridViewColumn(); oColumn.Header = itemFaultlist[i].TimeStamp.ToString("yyyy/MM"); oColumn.HeaderTextAlignment = TextAlignment.Center; oColumn.Width = 1000 / itemFaultlist.Count; oColumn.TextAlignment = TextAlignment.Center; oColumn.FooterTextAlignment = TextAlignment.Center; //动态添加一列的数据模板 StringBuilder sbTemp = new StringBuilder(); sbTemp.Append("<DataTemplate "); sbTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' "); sbTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' "); sbTemp.Append("xmlns:d='http://schemas.microsoft.com/expression/blend/2008' "); sbTemp.Append("xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' "); sbTemp.Append("xmlns:telerik='http://schemas.telerik.com/2008/xaml/presentation' >"); sbTemp.Append("<TextBlock Text=\"{Binding FaultCount}\"/>"); sbTemp.Append("</DataTemplate>"); DataTemplate dtTemplate = (DataTemplate)XamlReader.Load(sbTemp.ToString()); oColumn.CellTemplate = dtTemplate; rg_Fault.Columns.Add(oColumn); } rg_Fault.ItemsSource = list.Take(DefferList.Count); }