Click here to Skip to main content
11,410,118 members (52,541 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF DataGrid
Hi,

I wanted to Text wrap my columns of a Datagrid to a particular width. Please provide me any possible way to achieve this.


Thanks & Regards,
Mathi.
Posted 7-Jun-13 4:40am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,

Please refer to this[^] MSDN documentation. Basically If you are using a DataGridTextColumn, you need to define the Style for the DataGridTextColumn.ElementStyle.
<DataGrid.Columns>               
    <DataGridTextColumn Header="Wrapped & centered" Binding="{Binding field}">
        <DataGridTextColumn.ElementStyle>
             <Style>                            
                 <Setter Property="TextBlock.TextWrapping" Value="Wrap" />
                 <Setter Property="TextBlock.TextAlignment" Value="Center"/>
             </Style>
         </DataGridTextColumn.ElementStyle>
    </DataGridTextColumn>
</DataGrid.Columns>
Regards,
  Permalink  
v3
Comments
Sergey Alexandrovich Kryukov at 7-Jun-13 10:11am
   
5ed.
—SA
Prasad Khandekar at 7-Jun-13 10:13am
   
Thank you Sir.
Mathi2code at 11-Jun-13 2:00am
   
Hi Prasad,
Thanks for replying. The above is completely working good.
Could you please help me out in formatting the header text and its background. Like I want to make the header text alone to be bold and its background should be some color.

Please let me know the possible way to achieve.
Prasad Khandekar at 11-Jun-13 2:14am
   
Hello,

You can do this via HeaderStyle. Please see the MSDN link for more details. (http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridcolumn.headerstyle.aspx).

Regards,
Mathi2code at 11-Jun-13 16:23pm
   
Thanks Prasad

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 219
1 Maciej Los 128
2 OriginalGriff 120
3 Sascha Lefévre 120
4 BillWoodruff 60
0 Sergey Alexandrovich Kryukov 8,771
1 OriginalGriff 6,905
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 7 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100