locked
How to set the textblock with strikethrough in XAML or code?

    Question

  • Hi, dear all,

     

    I could set "underline" to a textblock control in xaml, but there is no way to set "strikethrough". There has been some discussions. A typical one is here. But it was Win8. Now we have been with Win8.1 update 1. The ability is still unavailable...

    Would anybody give me any hint to achieve this effect? Could we define a new style, or do it in code?

    Thanks!

    Wednesday, May 28, 2014 8:45 AM

Answers

  • If you can barcode then just draw a line over the TextBlock. Something like this (untested - you'll have to fiddle with the values, center the vertical alignment, etc.)
    <Grid>
       <TextBlock Text="https:" />
       <Line X1="0" Y1="0" X2="150" Y2="0" />
    </Grid>

    Wednesday, May 28, 2014 2:12 PM
    Moderator

All replies

  • There isn't built in support for strike through so you'll need to implement it yourself by drawing your own line. Whether you do this in Xaml or in code depends on your needs. In Xaml is easier but more static.
    Wednesday, May 28, 2014 12:07 PM
    Moderator
  • Hi, Rob, thank you very much! Would you please give me any hint? Or code illustrations? Thanks.
    Wednesday, May 28, 2014 1:42 PM
  • What is your scenario? How best to do this will depend on what you need it to do.

    Wednesday, May 28, 2014 1:50 PM
    Moderator
  • What I want to do is very simple:

    Just make the "https" with "strikethrough" if the certificate of the remote server is not trusted. I could put the "https" in a separate textblock.

    Thank you, Rob.

    Wednesday, May 28, 2014 1:59 PM
  • If you can barcode then just draw a line over the TextBlock. Something like this (untested - you'll have to fiddle with the values, center the vertical alignment, etc.)
    <Grid>
       <TextBlock Text="https:" />
       <Line X1="0" Y1="0" X2="150" Y2="0" />
    </Grid>

    Wednesday, May 28, 2014 2:12 PM
    Moderator
  • Rob, thank you very much for your info.

    I will have a try and update my result here.

    Wednesday, May 28, 2014 2:15 PM