I need to bind the column Header text of a DataGrid to a Resource string in a XAML file. Does anybody know if this is possible ?
The column Header definition looks like this but I would like to replace the "MyHeaderText" with text from a resource file:-
<data:DataGridTextColumn Header="MyHeaderText" Binding="{Binding SomeData}" IsReadOnly="True"/>
The Resource string would be set up in the UserControl.Resources section.
-
Have you tried anything like:
<data:DataGridTextColumn Header="{StaticResource SomeData}" IsReadOnly="True"/>Where "SomeData" is your resource.
cyberbobcat : I get the following error after trying this: AG_E_PARSER_BAD_PROPERTY_VALUE -
The header presentation area is limited. You can achieve this though by utilizing a string instead of a UIElement. Make sure you have the xmlns for the "System" namespace in your xaml file like so:
xmlns:sys="clr-namespace:System;assembly=mscorlib"Then have the following defined in your UserControl's Resources section:
<sys:String x:Key="MyHeader">My Header Text</sys:String>Then you can do basically what Sorskoot said and you shouldn't receive an error:
<data:DataGridTextColumn Header="{StaticResource MyHeader}" Binding="{Binding SomeData}" IsReadOnly="True" /> -
Note, you can do more than just use a text value if you want, but you need to use the HeaderStyle property instead of the Header Property.
0 comments:
Post a Comment