WPF DataGrid Cell Text Wrapping - set to NoWrap (False)

后端 未结 1 1000
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 17:26

How do I set the TextWrapping of every cell in a WPF DataGrid to \"NoWrap\"? I understand the Cell itself does not have a \"TextWrapping\" property, but I\'d like to set the pr

相关标签:
1条回答
  • 2021-01-23 18:09

    In the resources of your DataGrid, you can specify an alternative default style for TextBlocks. This should do what you require ("IF a TextBlock is being used, set its TextWrapping property to NoWrap"). This won't work if the TextBlocks explicitly specify a different style to be used.

    <DataGrid ...>
        <DataGrid.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="TextWrapping" Value="NoWrap"/>
            </Style>
        </DataGrid.Resources>
        ...
    </DataGrid>
    

    (Untested, since I do not have Visual Studio available right now.)

    0 讨论(0)
提交回复
热议问题