Reputation: 3009
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?
Upvotes: 0
Views: 1845
Reputation: 3009
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
Upvotes: 0
Reputation: 1299
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"
Upvotes: 1