在 Windows 应用商店应用程序中,是否有任何方法可以对 TextBlock 的内容应用删除线效果?如果没有,可以使用 RichTextBlock 或任何类似的控件。通过 XAML 还是以编程方式 (C#) 并不重要,但我更喜欢通过 XAML,这样它就会显示在设计器中。
我在微软的文档中找到了这个,但我不知道如何使用它: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.text.itextcharacterformat.strikethrough.aspx
Windows 应用商店应用程序有自己的控件命名空间 (System.Ui.Xaml.Controls)。您将看到 Windows 应用商店应用程序的 TextBlock 没有 TextDecoration 属性:TextBlock 文档。
“完整”.Net 4.5 TextBlock 确实具有 TextDecoration 属性:.Net 4.5 WPF TextBlock Documentation。
你可以用“hacky”的方式来做到这一点,如下所示:
<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>
看来终究是不可能的:
“我们将无法包含最终的 TextDecoration 类 了解 Windows 8 的 XAML 框架。这意味着您将 无法使用删除线功能,但您仍然可以 能够通过 Underline 类为文本添加下划线。”
但是,微软正在努力解决这个问题:
“这是 Windows 8 中 XAML 文本故事的已知限制 开发者预览。从好的方面来说,这是一个有规划的区域 很快就会发生改进,我们希望解决这个问题 问题。”
试试这个:
<TextBlock>TextBlock with <Span TextDecorations="Strikethrough">Strike through sample</Span></TextBlock>