【问题标题】:StrikeThrough effect on a TextBlockTextBlock 上的 StrikeThrough 效果
【发布时间】:2012-09-28 03:32:59
【问题描述】:

在 Windows 应用商店应用中,有什么方法可以对 TextBlock 的内容应用 StrikeThrough 效果?如果没有,RichTextBlock 或任何类似的控件都可以。无论是通过 XAML 还是以编程方式 (C#) 都没有关系,但我更喜欢通过 XAML 来显示在设计器中。

我在 Microsoft 的文档中找到了这个,但我不知道如何使用它: http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.text.itextcharacterformat.strikethrough.aspx

【问题讨论】:

    标签: c# .net xaml microsoft-metro windows-store-apps


    【解决方案1】:

    看来这毕竟是不可能的:

    "我们将无法在 final 中包含 TextDecoration 类 Realese for Windows 8 的 XAML 框架。这意味着您将 无法使用删除线功能,但您仍然可以 能够通过 Underline 类为文本添加下划线。”

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

    不过,微软正在努力解决这个问题:

    “这是 Windows 8 中 XAML 文本故事的已知限制 开发者预览。从好的方面来说,这是一个有计划的区域 此后不久将进行改进,我们希望解决此问题 问题。”

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

    【讨论】:

      【解决方案2】:

      Windows 应用商店应用拥有自己的控件命名空间 (System.Ui.Xaml.Controls)。您会看到适用于 Windows 应用商店应用的 TextBlock 没有 TextDecoration 属性:TextBlock documentation

      “完整”的 .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>
      

      【讨论】:

      • 感谢您的提示。我添加了一个Margin="0,10,0,0",该行直接出现在文本中。还删除了HorizontalAlignmentWidth 属性,使其填充父单元格并删除整个文本。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多