I'm trying to build a DataGrid layout where the first column's name will be dinamically changed. How can I do, into DataGridTextColumn's Header property, to change that? I've saw some examples than the Header property is connected into a StaticResource, but a StaticResource is a fixed value, and that's doesn't work for me, once what I need is several values. Example:
Remembering, this is one of several examples than i would need to change. Thanks.
This can be done easily with Databinding.
Create a property in the codebehind of your window to hold the string value; I will call mine TextProp. I will assume the elementname of your window is "Window" for this example. In the DataGridTextColumn tag, databind the Header attribute to that property.
<DataGridTextColumn Header="{Binding TextProp, ElementName=Window}"/>
Do the same as above, except put the property on your viewmodel to which the datagrid is bound. Change the XAML to:
<DataGridTextColumn Header="{Binding TextProp}"/>
Then all you have to do is change that Property value in whatever way you choose. To get this to update the value when the property changes, you will need to implement INotifyPropertyChanged (Check at the bottom of that post).