Daniel Ballinger
Daniel Ballinger

Reputation: 13537

Superscript and Subscript in WP7

I'm trying to show "H2O" with the 2 in subscript in a PivotItem Header.

E.g.

<controls:PivotItem Header="H20">
</controls:PivotItem>

I'd also like to assign the same value from code behind to TextBlock.Text.

E.g.

textBlock1.Text = "H2O"; // 2 to appear as subscript.

Is this possible with the version of Silverlight used for WP7?

Upvotes: 3

Views: 756

Answers (1)

Daniel Ballinger
Daniel Ballinger

Reputation: 13537

After some searching around I found a solution.

From SubScript and SuperScript in TextBlock by Troels Pedersen and lordcheeto respectively.

In the XAML the subscript 2 can be expressed via Unicode.

E.g.

<controls:PivotItem Header="H&#x2082;0">
</controls:PivotItem>

And similarly for the code behind.

E.g.

textBlock1.Text = "H\x2082O"; // 2 appears as subscript.

There are some limitations on this approach as only characters in the Basic Multilingual Plane (0000-FFFF) are supported and the font being used also needs to support the characters.

Upvotes: 6

Related Questions