ObservableCollection<string> RepcolumnName = new ObservableCollection<string>();
RepcolumnName.Add(ResourceFile.SrNoLevel);
RepcolumnName.Add(ResourceFile.EmpCodeLabel);
RepcolumnName.Add(ResourceFile.EmployeeNameLabel);
Binding binding = new Binding();
int index = 0; string bindCol = "";
foreach (var header in RepcolumnName)
{
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = header;
if (index == 0)
{ bindCol = "sNo"; }
else if (index == 1) { bindCol = "Empno"; }
else if (index == 2) { bindCol = "Name"; }
templateColumn.HeaderStyle = LayoutRoot.Resources["headerStyle"] as Style;
StringBuilder CellTemp = new StringBuilder();
CellTemp.Append("<DataTemplate ");
CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/");
CellTemp.Append("2006/xaml/presentation' ");
CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
CellTemp.Append("xmlns:local = 'clr-namespace:System.Windows.Controls");
CellTemp.Append(";assembly=System.Windows.Controls.Toolkit'>");
CellTemp.Append("<Grid>"); CellTemp.Append("<TextBlock ");
CellTemp.Append("Text ='{Binding Path=" + bindCol + "}' Style='{StaticResource ContentTextStyle}' IsHitTestVisible='False' ");
CellTemp.Append("Margin='4'/>");
CellTemp.Append("</Grid>");
CellTemp.Append("</DataTemplate>");
templateColumn.CellTemplate = (DataTemplate)XamlReader.Load(CellTemp.ToString());
DgvEmpData.Columns.Add(templateColumn);
index++; }
PagedCollectionView itemListView = new PagedCollectionView(FinalEmpList);
DgvEmpData.ItemsSource = itemListView;
if (itemListView.CanGroup == true) {
itemListView.GroupDescriptions.Add(new PropertyGroupDescription("DeptName"));
}