0

How do I databind a WPF Toolkit DataGrid column header value in code (not XAML)?

DataGridColumn fooColumn =  new DataGridTextColumn 
{
  Header = "Foo",
  Binding = new Binding {Path = new PropertyPath("BindingPath"), 
                         Mode = BindingMode.OneWay}
};

This databinds the content of the cells of the column. But how do I databind the header text ("Foo") itself (to, say, a string property on a viewmodel)?

1 Answer 1

1
DataGridColumn fooColumn =  new DataGridTextColumn 
{
  Binding = new Binding {Path = new PropertyPath("BindingPath"), 
                         Mode = BindingMode.OneWay}
};

BindingOperations.SetBinding(fooColumn, DataGridColumn.HeaderProperty, new Binding("Foo") { Source = yourViewModel} );
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.