Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何通过后面的代码更改 WPF DataGrid 列标题文本?我尝试了下面的代码,但它不起作用。
this.sampleDataGrid.Columns[0].Header = "New Header"; this.sampleDataGrid.Refresh();
如果您的 DataGridColumn 是一个模板,那么您需要在代码中更改它的模板。
var template = new DataTemplate(); template.VisualTree = new FrameworkElementFactory(typeof(TextBlock)); template.VisualTree.SetValue(TextBlock.TextProperty, "New Header"); dataGrid.Columns[0].HeaderTemplate = template;