I need to format some string in Superscript (code behind) in c#,
for example,
Input => 100 Output => 10^2
where Output<string> is a Clr Property
I have tried with the below code snippet,
TextBlock _textBlock = new TextBlock();
_textBlock.Text = "10";
_textBlock.Inlines.Add(new Run() { BaselineAlignment = BaselineAlignment.Superscript, Text = "2"});
As Typography is Read Only property in the above case, i can't set the Typography.Variants in code behind.
Note: Please do note that this question is not about rendering, this is about reading the Text as string. Expected value is 10^2. While suggesting duplicates please check other question addresses this.
Could any one guide me on this?
And also while set BaselineAlignment.Superscript like the above mentioned code snippet, it doesn't render like the superscript (small font) instead it renders in the same FontSize (instead it looks like setting the Margin property for the superscript content alone like new Thickness(0,0,0,FontSize) )
You need to use the Unicode character for superscript 2. Have a look here: http://msdn.microsoft.com/en-us/library/aa664669%28v=vs.71%29.aspx
If you want it in a string literal you could use:
var value = "10\xB2";
Live Demo
In WPF you can use Typeography variants.
Set superscript and subscript in formatted text in wpf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With