Superscript / subscript in hyperlink in WPF

You can use the superscript unicode characters (e.g. http://www.fileformat.info/info/unicode/char/b2/index.htm)

Like this:

<TextBlock FontSize="30" FontFamily="Segoe UI">
  <Hyperlink>
      Apply R² Calculation
  </Hyperlink>
</TextBlock>

Result:

Result image

Obviously this will not work unless what you are super scripting actually has a unicode superscript character.


If the hyperlink isn't going to wrap to more than one line, then embedding another TextBlock can work:

<TextBlock FontSize="30" FontFamily="Palatino Linotype">
  <Hyperlink>
    <TextBlock>
      R<Run BaselineAlignment="Superscript" FontSize="12pt">2</Run>
    </TextBlock>
  </Hyperlink>
</TextBlock>

This will give a solid hyperlink under the Hyperlink's child, which means an unbroken hyperlink:

However, if the embedded TextBlock needs to wrap to multiple lines, you'll only get one underline under the entire wrapped paragraph, rather than underlining each line of text:


(source: excastle.com)

If you can put a TextBlock only around a short bit of content that needs superscripts -- e.g., around just the R^2 in the above example -- and leave the rest of the text parented to the hyperlink, then you get underlining as normal. But sometimes that's not practical, so it's something to watch out for.

Tags:

Fonts

Wpf

Xaml