Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to set a strikethrough on individual cells of the WPF DataGrid?

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

...

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 there any way to access the TextBlock generated using the default DataGridTextColumn?

like image 404
SDK Avatar asked Apr 20 '11 13:04

SDK


1 Answers

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

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

like image 126
H.B. Avatar answered Oct 01 '22 08:10

H.B.