Perform the following steps to create groups while displaying records in DataGrid:
- Inside the project, create the Employee model class and expose some properties, like we shared earlier in the Sorting data in a DataGrid control recipe.
- Create the same dependency property (Employees, of type ObservableCollection<Employee>) in the MainWindow.xaml.cs file and populate the collection with some data records.
- Now open the MainWindow.xaml file and add the attribute x:Name="window" to give the Window a name, so that we can perform element-to-element data binding.
- Replace the default Grid panel with StackPanel and add a DataGrid control inside it.
- Set the ItemsSource property of the DataGrid to bind the Employees collection, exposed from the code behind as a dependency property:
ItemsSource="{Binding Employees, ElementName=window}"
- Set the AutoGenerateColumns of the data grid to False, as we are going to add the columns manually.
- As shown in the following...