Here’s the code:
static readonly char[] s_expChar = "eE".ToCharArray();
static void setValue( TextBlock target, double val )
{
string text = val.ToString();
int indE = text.IndexOfAny( s_expChar );
if( indE > 0 )
{
string normal = text.Substring( 0, indE ) + "·10";
string ss = text.Substring( indE + 1 );
if( ss.StartsWith( "0" ) )
ss = ss.Substring( 1 );
else if( ss.StartsWith( "-0" ) )
ss = "-" + ss.Substring( 2 );
target.Inlines.Clear();
target.Inlines.Add( new Run( normal ) );
Run rSuper = new Run( ss );
Typography.SetVariants( rSuper, FontVariants.Superscript );
target.Inlines.Add( rSuper );
}
else
{
target.Text = text;
}
}
Here's the output:
As you see, vertical alignment of the -
character is broken, seems not affected by FontVariants.Superscript
. How to fix?
In debugger in live visual tree, I see 2 runs with the correct values, i.e. the second one has text -6
including the -