Posts Tagged ‘Strikethru’

I had the need today to display strikethrough text in a Xamarin Forms app. The built-in label control didn’t support such formatting. So, leaning on Unicode’s strikethrough character set, I wrote a function to convert any string to a strikethrough string. To be fair, this works great for the normal character set, so I feel it’s good for most things. Please let me know if your mileage varies.

Business case: I needed to show a “Was some dollar amount” value. Like “Was $BLAH, and Now BLAH!”

In my class, I simply called into my strikethrough converter, as follows:

The property:

public string StrikeThroughValueText => StrikeThroughValue.HasValue ? $"{ConvertToStrikethrough(StrikeThroughValue.Value.ToString("C"))}" : "???";

The function:

private string ConvertToStrikethrough(string stringToChange)
    var newString = "";
    foreach (var character in stringToChange)
        newString += $"{character}\u0336";
    return newString;

Enjoy! I hope this helps you 🙂

Link: More about why this works: Combining Long Stroke Overlay.