对WPF DataGrid的单个单元格进行删除的最佳方法? [英] Best way to set a strikethrough on individual cells of the WPF DataGrid?

查看:220
本文介绍了对WPF DataGrid的单个单元格进行删除的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WPF DataGrid的单个单元格上,将字体设置为删除线样式的最佳(简单)方法是什么?

What is the best (easy) way to set the font to a strikethrough style on individual cells of the WPF DataGrid?

...

我知道的选项是在单个单元格中插入TextBlock控件或使用DataGridTemplateColumn - 并在其中使用TextDecorations属性。无论哪种方式这是一个使命,我想使用DataGrid的默认AutoGenerate Columns函数,特别是因为我的ItemsSource是一个DataTable。

Options that I'm aware of are inserting TextBlock controls in individual cells or using a DataGridTemplateColumn - and using the TextDecorations property therein. Either way this is quite a mission, I'd like to use the default AutoGenerate Columns function of DataGrid, especially since my ItemsSource is a DataTable.

As and aside,is有没有办法访问使用默认DataGridTextColumn生成的TextBlock?

As and aside, is there any way to access the TextBlock generated using the default DataGridTextColumn?

推荐答案

<DataGridTextColumn Binding="{Binding Name}">
    <DataGridTextColumn.ElementStyle>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="TextDecorations" Value="Strikethrough"/>
        </Style>
    </DataGridTextColumn.ElementStyle>
</DataGridTextColumn>

当然,您可以用DataTrigger包装设置器,以便有选择地使用它。

Of course you can wrap the setter in a DataTrigger to use it selectively.

这篇关于对WPF DataGrid的单个单元格进行删除的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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