[英]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: 有什么方法可以将DataGridColumns的标题绑定到这些绑定到本地方法的事件,例如:
<data:DataGridTextColumn Header="{Binding TYPE_HEADER}" />
Can this be done? 能做到吗? Perhaps by using some dynamic ResourceDictionary or something?
也许通过使用一些动态的ResourceDictionary之类的东西?
the TYPE_HEADER must be a string property (it can be backed by a const). TYPE_HEADER必须是字符串属性(可以由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. 如果Silverlight支持x:Static会更容易,但是不支持。 see Silverlight 4 Equivalent to WPF "x:static"
请参见Silverlight 4等效于WPF“ x:static”
It appears this cannot be done without editing the control template for DataGridTextColumn as Header is not a FrameworkElement... 似乎如果不编辑DataGridTextColumn的控件模板就无法完成此操作,因为Header不是FrameworkElement ...
Dynamically setting the Header text of a Silverlight DataGrid Column 动态设置Silverlight DataGrid列的标题文本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.