Если вы хотите привязать зачеркивание на основе определенной ячейки, у вас есть проблема с привязкой, потому что DataGridTextColumn.Binding изменяет только содержимое TextBox.Text.Если значение свойства Text - это все, что вам нужно, вы можете связать его с самим TextBox:
<Setter Property="TextDecorations"
Value="{Binding RelativeSource={RelativeSource Self},
Path=Text,
Converter={StaticResource TextToTextDecorationsConverter}}" />
Но если вы хотите связать что-то отличное от TextBox.Text, вам нужно связать через DataGridRow,который является родителем TextBox в визуальном дереве.DataGridRow имеет свойство Item, которое дает доступ ко всему объекту, используемому для всей строки.
<Setter Property="TextDecorations"
Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}},
Path =Item.SomeProperty,
Converter={StaticResource SomePropertyToTextDecorationsConverter}}" />
Преобразователь выглядит следующим образом, предполагая, что что-то имеет тип boolean:
public class SomePropertyToTextDecorationsConverter: IValueConverter {
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
if (value is bool) {
if ((bool)value) {
TextDecorationCollection redStrikthroughTextDecoration =
TextDecorations.Strikethrough.CloneCurrentValue();
redStrikthroughTextDecoration[0].Pen =
new Pen {Brush=Brushes.Red, Thickness = 3 };
return redStrikthroughTextDecoration;
}
}
return new TextDecorationCollection();
}
public object ConvertBack(object value, Type targetType, object parameter,
CultureInfo culture)
{
throw new NotImplementedException();
}
}