【问题标题】:WPF DataGrid Cell Text Wrapping - set to NoWrap (False)WPF DataGrid 单元格文本换行 - 设置为 NoWrap (False)
【发布时间】:2011-05-11 00:32:18
【问题描述】:

如何将 WPF DataGrid 中每个单元格的 TextWrapping 设置为“NoWrap”?我了解单元格本身没有“TextWrapping”属性,但我想在单元格内的控件上设置该属性。

我正在使用的 DataGrid 没有明确定义的列,它显示的结果集是动态的。

我正在寻找类似于以下链接中提供的答案的解决方案。但是我不想显式覆盖单元格样式/模板并定义要使用的控件。相反,我想说,如果正在使用 TextBlock,请将其 TextWrapping 属性设置为 NoWrap。

WPF toolkit datagrid cell text wrapping
How do I enable text wrapping on all column headers?

【问题讨论】:

    标签: wpf wpfdatagrid word-wrap datagridcell


    【解决方案1】:

    在 DataGrid 的资源中,您可以为 TextBlocks 指定另一种默认样式。这应该满足您的要求(“如果正在使用 TextBlock,请将其 TextWrapping 属性设置为 NoWrap”)。如果 TextBlock 明确指定要使用的不同样式,这将不起作用。

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

    (未经测试,因为我现在没有可用的 Visual Studio。)

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 2018-04-14
      相关资源
      最近更新 更多