Set superscript and subscript in formatted text in wpf

后端 未结 8 546
时光说笑
时光说笑 2020-11-27 06:37

How can I set some text as subscript/superscript in FormattedText in WPF?

相关标签:
8条回答
  • 2020-11-27 07:14

    Setting for superscript works fine with the following code:

    <TextBlock Text="(cm"  />
    <TextBlock ><Span BaselineAlignment="Top" FontSize="8">2</Span></TextBlock>
    <TextBlock Text=")" />
    

    Setting the Baseallignment for subscript in the Span tag did not work for me. I tried the following code and it worked fine.

      <TextBlock Text="H"  />
      <TextBlock Text="2" Margin="-2,0,-2,0" TextBlock.LineHeight="3" >   
      <TextBlock Text="O" />
    
    0 讨论(0)
  • 2020-11-27 07:16

    It's interesting to note that for some characters (m2, m3, etc) a superscript is not needed, but the unicode character can be used. For example:

    <Run Text=" m&#x00B3;" />
    

    This would show m3.

    0 讨论(0)
提交回复
热议问题