Silverlight datagrid header binding to constant

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?

Answers


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 http://stackoverflow.com/questions/3373926/silverlight-4-equivalent-to-wpf-xstatic


Need Your Help

JavaScript and Check Boxes not working

javascript checkbox

Basically I am trying to make a form in HTML that uses JavaScript to take input from check boxes and open a specific page on my site depending on which boxes are checked.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.