This project is read-only.

Write subscript or superscript in textblock

Sep 17, 2013 at 2:50 PM
Hi,

I'm writing a mathematical application and need to use subscript or superscript for some labels and textblocks. For example, I'm trying to write "At" with the "t" subscript.

I've tried using this code :
<TextBlock >
        A<Run Typography.Variants="Subscript">t</Run>
</TextBlock>
But it doesn't work. It seems that the default font used for m:ui doesn't support subscript variant.

Is there an alternative font that I could use that would support sub/superscript (OpenFont) that would give the "modern" feeling, or is there an alternative technique?

I've tested playing with the font size, but this feels really like a hack.

If there is another font I can use, how do I set another font for m:ui?

Thanks.
Sep 18, 2013 at 11:31 AM
After a few more research I have found that the Segoe UI font available on Windows 7 doesn't have superscript or subscript support. The code would work perfectly on Windows 8, but not on Windows 7 (Windows 8 has an updated version of Segoe UI). Unfortunately I haven't found a way to update Windows 7 Segoe font to have the same behavior as Win 8.

For reference, I have found a workaround, which is kind of a hack and might give performance issues, but at least it works with any fonts.

I define 2 styles that I use on my "Run" inside Textblock elements.
    <Style x:Key="Superscripted" TargetType="Run">
        <Setter Property="BaselineAlignment" Value="Top" />
        <Setter Property="FontSize" Value="9" />
    </Style>
    <Style x:Key="Subscripted" TargetType="Run">
        <Setter Property="BaselineAlignment" Value="Subscript" />
        <Setter Property="FontSize" Value="9" />
    </Style>
As you can see, I have used "Top" for the BaselineAlignment instead of "Superscript" because superscript makes it go higher than the other letters and it doesn't look good.

The usage:
<TextBlock>
         cm<Run Style="{StaticResource Superscripted}">2</Run>
</TextBlock>
I'm open to any better suggestion on how to achieve that without going through this stupid hack.