Strikethrough on celltext

Sep 12, 2009 at 10:49 AM


First of all, I'm fairly new to WPF, so I'm in a learning progress, and not familiar with everything yet, so this may be an easy question to answer!

SO, to the question!

I have some rows I need to have a strikethrough text on, but can't figure out how to set the style. My columns is DataGridTextColumn, so it contains a TextBlock which has the ability to have a TextDecoration, but I can't figure out how.

I have search a bit around, but didn't find any useful information to do this. Since I'm new to WPF I can't tell if this is a DataGrid question or a general WPF question.


Apr 18, 2012 at 8:02 PM
Edited Apr 18, 2012 at 8:10 PM

I know it is about 3 years too late but... Here is a render expensive way to do what you are interested in doing.

1. Define a TextBox style for the DataGridTextColumn's text box, or any other TextBox whose DataContext contains the bound property...

    <Style x:Key="DataGridTextColumnTextBoxStyle" TargetType="{x:Type TextBlock}">
            <DataTrigger Binding="{Binding SomeBool}" Value="True">
                <Setter Property="TextDecorations">
                            <TextDecoration Location="Strikethrough" >
                                    <Pen Thickness="2" Brush="{DynamicResource ItronBlackSolidColorBrush}"/>
            <DataTrigger Binding="{Binding SomeBool}" Value="False">
                <Setter Property="TextDecorations" Value="None"/>

2. The apply it to your TextBox, or in this case the ElementStyle for the DataGridTextColumn

                <DataGridTextColumn Header="{x:Static Properties:Resources.ColumnHeader}" 
="{Binding BoundProperty}" 
="{DynamicResource DataGridTextColumnTextBoxStyle}" />

Rending seems to really slow down since each TextBox has to evaluate the bound property, in this case "SomeBool". It is possible but very fast...