0

Say I have a bunch of local constants in my code behind that I want to use as headers, for example:

const string TYPE_HEADER = "Type";
const string LOCATION_ HEADER = "Location";

etc.

Is there any way I can bind the headers of my DataGridColumns to these like events are bound to local methods, for example:

<data:DataGridTextColumn Header="{Binding TYPE_HEADER}" />

Can this be done? Perhaps by using some dynamic ResourceDictionary or something?

PhilBrown
  • 2,949
  • 7
  • 34
  • 53

2 Answers2

1

the TYPE_HEADER must be a string property (it can be backed by a const). make a container:

public class MyStaticDataProvider
{
public string TYPE_HEADER { get { return "blkajsd"; } }
}

below the declaration of your usercontrol:

<UserControl.Resources>
<ResourceDictionary>
 <MyNamespace:MyStaticDataProvider x:Key="NameProvider" />
</ResourceDictionary>
</UserContro.Resources>

for your header:

Header="{Binding Path=TYPE_HEADER, Source={StaticResource NameProvider}, Mode=OneTime}"

it would be easier if silverlight supported x:Static, but it does not. see Silverlight 4 Equivalent to WPF "x:static"

Community
  • 1
  • 1
Alex Lo
  • 1,299
  • 8
  • 10
0

It appears this cannot be done without editing the control template for DataGridTextColumn as Header is not a FrameworkElement...

Dynamically setting the Header text of a Silverlight DataGrid Column

Community
  • 1
  • 1
PhilBrown
  • 2,949
  • 7
  • 34
  • 53