Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StrikeThrough effect on a TextBlock

In a Windows Store App, is there any way to apply a StrikeThrough effect on a TextBlock's content? If there isn't, a RichTextBlock or any similar controls would do. It doesn't matter if it's through XAML or programmatically (C#), but I'd prefer through XAML so it would show in the designer.

I found this among Microsoft's documentation, but I don't know how to use it: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.text.itextcharacterformat.strikethrough.aspx

like image 826
dcastro Avatar asked Oct 07 '12 19:10

dcastro


People also ask

How to use strikethrough text decoration in text block?

' Use the default font values for the strikethrough text decoration. Private Sub SetDefaultStrikethrough () ' Set the underline decoration directly to the text block. TextBlock1.TextDecorations = TextDecorations.Strikethrough End Sub <!--

What is strikethrough text generator?

Strikethrough text generator (̶S̶t̶r̶i̶k̶e̶-̶t̶h̶r̶o̶u̶g̶h̶) Strikethrough text generator (̶S̶t̶r̶i̶k̶e̶-̶t̶h̶r̶o̶u̶g̶h̶) This is an online text generator which can convert the text to various of text style, include Strike-through, Underline and the slash symbol.

How do I strikethrough text in word?

Select the text that you want to format. Go to Home > Strikethrough. Apply or remove double-line strikethrough formatting Select the text that you want to format.

What is the default font size for strikethrough text decoration?

Use the default font values for the strikethrough text decoration. --> <TextBlock TextDecorations="Strikethrough" FontSize="36" > The quick red fox </TextBlock> The following example shows the location of a strikethrough text decoration relative to the text.


2 Answers

Windows Store apps have their own control namespace (System.Ui.Xaml.Controls). You'll see that the TextBlock for Windows Store apps doesn't have a TextDecoration property: TextBlock documentation.

The "full" .Net 4.5 TextBlock does have a TextDecoration property:.Net 4.5 WPF TextBlock Documentation.

You can do this in a "hacky" way like so:

    <Grid Height="30">
        <TextBlock Text="This is a test" FontSize="22" Height="34" HorizontalAlignment="Center" Foreground="White"   />
        <Line Stretch="Fill" Stroke="white" StrokeThickness="2 " X1="1" Width="120" VerticalAlignment="Center"  HorizontalAlignment="Center"   />
    </Grid>
like image 198
Faster Solutions Avatar answered Oct 02 '22 07:10

Faster Solutions


It seems it isn't possible after all:

"we will not able to include the TextDecoration class for the final realese of the XAML framework for Windows 8. This means that you will not be able to use the strikethrough feature, but you will still be able to underline text via the Underline class."

(http://social.msdn.microsoft.com/Forums/en-CA/winappswithcsharp/thread/cba0c363-60da-4e4e-9fc1-93f7c3658aff)

However, Microsoft is working on this:

"This is a known limitation in XAML text story in the Windows 8 developer preview. On the bright side this is an area with planned improvements happening soon hereafter and we expect to resolve this issue."

(http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/d5362fe2-48f6-448d-92ae-25216345c46d)

like image 35
dcastro Avatar answered Oct 02 '22 09:10

dcastro