【问题标题】:wpf c#: label with superscript and subscript [duplicate]wpf c#:带有上标和下标的标签[重复]
【发布时间】:2013-06-18 15:57:48
【问题描述】:

在我的基于 C# 的 WPF 应用程序中,我需要一些带有上标和下标的标签,就像在各种数学运算中一样。例如:

Es/Em

4x

我需要了解如何在 XAML 和代码中以这种方式创建标签。 任何人都可以帮助我吗?我只发现了一些有关 Windows 窗体的信息,但没有发现有关 WPF 的信息。 感谢您的帮助

编辑: 另一篇文章仅描述了 XAML 解决方案,这对我不起作用。我是否需要更改字符的大小以具有下标/上标?另外,我需要有一个解决方案来通过代码创建带有上标/下标的标签,而不仅仅是通过 XAML。

【问题讨论】:

  • 我已经为 XAML 尝试了该代码,但它不起作用。

标签: c# wpf label subscript superscript


【解决方案1】:

使用 Typography.Variants,这意味着具有下标/上标样式渲染。 Ref.

MDSN 示例

<Paragraph FontFamily="Palatino Linotype">
  2<Run Typography.Variants="Superscript">3</Run>
  14<Run Typography.Variants="Superscript">th</Run>
</Paragraph>

<Paragraph FontFamily="Palatino Linotype">
  H<Run Typography.Variants="Subscript">2</Run>O
  Footnote<Run Typography.Variants="Subscript">4</Run>
</Paragraph>

【讨论】:

  • 我试过这个&lt;TextBlock&gt;&lt;Run&gt;Normal Text&lt;/Run&gt;2&lt;Run Typography.Variants="Superscript"&gt;3&lt;/Run&gt;3&lt;Run Typography.Variants="Subscript"&gt;4&lt;/Run&gt;&lt;/TextBlock&gt; 但它对我不起作用。段落在 Visual Studio 中不存在,我无法通过 XAML 中的代码添加它。
  • 引用相关的命名空间,在本例中是 System.Windows.Documents(在 PresentationFramework.dll 中)。参考:msdn.microsoft.com/en-us/library/…
  • 完成,但 IDE 告诉我无法分配指定的值。
  • 在您上一条评论的链接中,页面底部示例中没有引用命名空间 System.Windows.Documents。
  • 为了解决问题,我在 XAML 中使用了 BaselineAlignment 指令。现在我需要知道如何在 C# 中使用它,因为我需要用以下文本编写文本块:ag (g) with first 'g' as subscript...please help
猜你喜欢
  • 2015-02-11
  • 1970-01-01
  • 2015-10-10
  • 2010-12-06
  • 1970-01-01
  • 2014-02-12
  • 2016-04-25
  • 2020-01-19
  • 1970-01-01
相关资源
最近更新 更多