Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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

1 solution

Hello,

Please refer to this[^] MSDN documentation. Basically If you are using a DataGridTextColumn, you need to define the Style for the DataGridTextColumn.ElementStyle.
XML
<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,
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 7-Jun-13 10:11am    
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900