How can i set some text as subscript/superscript in FormattedText in wpf
相关问题
- VNC control for WPF application
- WPF Binding from System.Windows.SystemParameters.P
- XAML: Applying styles to nested controls
- How can I add a horizontal line (“goal line”) for
- How to properly change a resource dictionary
You use Typography.Variants:
It's interesting to note that for some characters (m2, m3, etc) a superscript is not needed, but the unicode character can be used. For example:
This would show m3.
Setting for superscript works fine with the following code:
Setting the Baseallignment for subscript in the Span tag did not work for me. I tried the following code and it worked fine.
I used a layout transform, because
Typography.Variants
often doesn't work:The advantage of using a
LayoutTransform
is that it is insensitive to the fontsize. If the fontsize is changed afterwards, this superscript works where explicit FontSize setting breaks.Typography.Variants works only for open type fonts. If you dont like your superscripts/subscripts going outside the height of actual text then you can use something like the following:
You can use something like
<TextBlock>5x<Run BaselineAlignment="Superscript">4</Run> + 4</TextBlock>
.However, as far as I know, you will have to reduce the font-size yourself.