Skip to main content
Home Forums General Silverlight Installation and Setup TexWrapping on DataGridTemplateColumn Header
2 replies. Latest Post by Soennichsen on September 25, 2009.
(0)
cgove@op...
Member
47 points
12 Posts
10-27-2008 4:40 PM |
Hello, I'm trying to get my DataGridTemplateColumn Headers to wrap. I've been reading a lot of posts from others having issues but don't seem to see any definitive answer. (at least for the RTW version i'm using). Heres where i',m at:
<
I Get This error when loading the Xaml
System.InvalidOperationException: System.NotSupportedException: Content does not support UIElements, use ContentTemplate instead. at ....
I wrapped the Textblock in the Header in a <DataTemplate> as suggested by another post, but I got the same errors.
Can anyone tell me how to do this?
Yi-Lun L...
All-Star
25052 points
2,747 Posts
10-29-2008 12:15 AM |
Hello, you should use a HeaderStyle. Something like this:
<data:DataGridTemplateColumn Header="something"><data:DataGridTemplateColumn.HeaderStyle><Style TargetType="datap:DataGridColumnHeader"><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="datap:DataGridColumnHeader"><TextBlock Text="{TemplateBinding Content}" TextWrapping="True"/></ControlTemplate></Setter.Value></Setter></Style></data:DataGridTemplateColumn.HeaderStyle></data:DataGridTemplateColumn>
Note DataGridColumnHeader is defined in System.Windows.Controls.Primitives namespace. So you must include a namespace mapping like this one:
xmlns:datap="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
Soennichsen
16 points
9 Posts
09-25-2009 6:27 AM |
For me the following code does work better:
<data:DataGridTemplateColumn.HeaderStyle> <Style TargetType="datap:DataGridColumnHeader"> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <TextBlock Text="{Binding}" TextWrapping="Wrap"/> </DataTemplate> </Setter.Value> </Setter> </Style> </data:DataGridTemplateColumn.HeaderStyle>
Sven