【发布时间】:2019-09-22 20:40:48
【问题描述】:
代码如下:
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;
}
}
这是输出:
如您所见,- 字符的垂直对齐被破坏,似乎不受FontVariants.Superscript 的影响。如何解决?
在实时可视化树的调试器中,我看到 2 次运行具有正确的值,即第二次运行文本 -6,包括 -
【问题讨论】:
-
Typography.Variants是出了名的越野车 stackoverflow.com/questions/2095583/…