显示上标和下标 [英] Displaying super- and subscript

查看:26
本文介绍了显示上标和下标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个 UWP 应用,该应用也处理数学问题.因此,我解析公式并将它们显示为 RichTextBlock 中的 inlines.可以想象,我也想显示订阅和订阅 - 但我还没有找到这样做的方法.我知道,WPF 中有一种叫做 BaselineAlignment 的东西,但似乎 UWP 不支持它.我目前也即将弄清楚如何最好地显示分数线和根.我已经考虑过为此目的构建自己的控件,但如果有人知道更好的方法,我会很高兴知道.我很高兴得到任何答复.

解决方案

要将下标和上标应用于 RichTextBlock 中的文本,我们可以利用

I'm currently working on an UWP app which also deals with math. Therefore i parse formulae and display them as inlines in a RichTextBlock. As you can imagine, I also want to display sub- and superscription - but I haven't yet found a way to do so. I know, there is something called BaselineAlignment in WPF, but it seems that this is not supported in UWP. I'm currently also about to figure out how to best display fraction lines and roots. I've thought about building my own control for this purpose, but if somebody knows a better approach it would be nice to know. I'm gladful for any answer.

解决方案

To apply subscript and superscript to text in RichTextBlock, we can take advantage of Typography.Variants attached property. For example:

<RichTextBlock FontSize="36">
    <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>
</RichTextBlock>

And the output would like:

这篇关于显示上标和下标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆