如何文本包装WPF DataGrid的所有列 [英] How to Text Wrap all the Columns of a WPF DataGrid

查看:67
本文介绍了如何文本包装WPF DataGrid的所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想将Datagrid的列文本换行到特定宽度。请告诉我任何可行的方法来实现这个目标。





谢谢和问候,

Mathi。

解决方案

你好,



请参考这个 [ ^ ] MSDN文档。基本上如果您使用的是DataGridTextColumn,则需要为DataGridTextColumn.ElementStyle定义样式。

 <   DataGrid.Columns  >  
< ; DataGridTextColumn 标题 < span class =code-keyword> = Wrapped& centered 绑定 = {Binding field} >
< DataGridTextColumn.ElementStyle >
< 样式 >
< < span class =code-leadattribute> Setter Property = TextBlock.TextWrapping = 换行 / >
< Setter 属性 = TextBlock.TextAlignment VALU e = 中心 / >
< / Style >
< /DataGridTextColumn.ElementStyle>
< / DataGridTextColumn >
< / DataGrid.Columns >



问候,


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.

解决方案

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,


这篇关于如何文本包装WPF DataGrid的所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆