Click here to Skip to main content
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 OriginalGriff 7,800
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 7 Jun 2013
Copyright © CodeProject, 1999-2014
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