3

How can i change the WPF DataGrid Column Header Text via code behind? i tried the code below but its not working.

this.sampleDataGrid.Columns[0].Header = "New Header"; 
this.sampleDataGrid.Refresh();
2
  • Works fine here. is your DataGridColumn using a Template for header? Commented Nov 2, 2012 at 9:51
  • Yes.The DataGrid is a customized one. Commented Nov 2, 2012 at 9:55

1 Answer 1

3

If your DataGridColumn is a Template then you need to change its Template in code.

    var template = new DataTemplate();
    template.VisualTree = new FrameworkElementFactory(typeof(TextBlock));
    template.VisualTree.SetValue(TextBlock.TextProperty, "New Header");
    dataGrid.Columns[0].HeaderTemplate = template;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.