Skip to main content

Microsoft Silverlight

Answered Question TexWrapping on DataGridTemplateColumn HeaderRSS Feed

(0)

cgove@optonline.net
cgove@op...

Member

Member

47 points

12 Posts

TexWrapping on DataGridTemplateColumn Header

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:

<data:DataGridTemplateColumn Width="90">

<data:DataGridTemplateColumn.Header>

<TextBlock Text="x  y  x" TextWrapping="Wrap" />

</data:DataGridTemplateColumn.Header>

<data:DataGridTemplateColumn.CellTemplate>

<DataTemplate>

<TextBlock Text="{Binding zzz, Converter={StaticResource currencyConverter}}" HorizontalAlignment="Right" />

</DataTemplate>

</data:DataGridTemplateColumn.CellTemplate>

<data:DataGridTemplateColumn.CellEditingTemplate >

<DataTemplate >

<TextBox Text="{Binding zzz,Mode=TwoWay, Converter={StaticResource currencyConverter}}" HorizontalAlignment="Right" />

</DataTemplate>

</data:DataGridTemplateColumn.CellEditingTemplate>

</data:DataGridTemplateColumn>

 

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?

CGOVE

Yi-Lun Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Answered Question

Re: TexWrapping on DataGridTemplateColumn Header

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"

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

Soennichsen
Soennichsen

Member

Member

16 points

9 Posts

Re: TexWrapping on DataGridTemplateColumn Header

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

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities