StrikeThrough effect on a TextBlock
Asked Answered
I

3

6

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

Isaacson answered 7/10, 2012 at 19:51 Comment(0)
T
16

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>
Tomika answered 7/10, 2012 at 21:3 Comment(1)
Thanks for the tip. I added a Margin="0,10,0,0" and the line appears right through the text. Also removed the HorizontalAlignment and Width properties to make it fill the parent cell and strike through the entire text.Isaacson
I
3

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)

Isaacson answered 7/10, 2012 at 20:43 Comment(0)
M
0

Simply try this :

<TextBlock>TextBlock with <Span TextDecorations="Strikethrough">Strike through sample</Span></TextBlock>

Here is the documentation about TextDecorations.Strikethrough property

Meet answered 14/10, 2023 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.