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
' 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 <!--
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.
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.
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.
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>
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With