Click here to Skip to main content
12,406,592 members (49,038 online)
Rate this:
 
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 3: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
   
5ed.
—SA
Prasad Khandekar 7-Jun-13 10:13am
   
Thank you Sir.
Mathi2code 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 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160730.1 | Last Updated 7 Jun 2013
Copyright © CodeProject, 1999-2016
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