Before reading this article, I highly recommend reading the previous parts:
AutoGenerateColumnsThe AutoGenerateColumns property determines whether the DataGrid columns will be autogenerated at run-time based on the data source object and its properties. Each public property of the data source collection becomes a column in the DataGrid. The DataGrid control is smart enough to know what type of column to generate for various data types. As you saw in Figure 4, the DataGrid generated 5 columns for 5 public properties of the Author class and a CheckBox column was generated for a book type IsMVP property. Note: The AutoGenerateColumns value is set to true by default for a DataGrid.The XAML code snippet in Listing 7 sets the AutoGenerateColumns to True.
Let's look at the output of some of these values. Figure 8 is the result of ColumnWidth="SizeToHeader".Figure 8Figure 9 is the result of ColumnWidth="SizeToCells".Figure 9Figure 10 is the result of ColumnWidth="100".Figure 10Figure 11 is the result of ColumnWidth="*".Figure 11CanUserResizeColumnsBy default, the DataGrid allows users to resize its columns and rows. But you can restrict users if they can resize the DataGrid columns and rows. The CanUserResizeRows property is used to set whether or not users can resize the row. The CanUserResizeColumns property is used to set whether or not users can resize the columns. The code snippet in Listing 13 restricts users from resizing the rows and columns of the DataGrid.