如何在代码后面更改DataGrid列的标题?
示例:
var dataGrid = new DataGrid();
dataGrid.ItemsSource = someRecords;
// ... now I want to change a column header ...
答案 0 :(得分:3)
我会使用您的绑定项目类的DisplayName
,如下所示
public class YourItemClass
{
[DisplayName("Column Name")]
public string SomeProperty{ get; set; }
}
答案 1 :(得分:2)
使用DataGrid.Columns:
dataGrid.Columns[0].Header = "New Header for column 0";
答案 2 :(得分:1)
您可以在Page_Load
dataGrid.HeaderRow.Cells[0].Text = "Any thing that you want to Enter";