1

In my WPF application, C# based, I need to have some labels with superscript and subscript, as usually in various maths operations. For example:

Es/Em

or

4x

I need to understand how to create labels int this way both in XAML and via code. Anyone can help me? I only found something about Windows Forms, but nothing about WPF. Thanks for your help

EDIT: The other post describes only XAML solution, that does not work for me. Do I need to change size of characters to have subscript / superscript??Plus, I need to have a solution to create label with superscript / subscript via code and not only via XAML.

FrancescoDS
  • 1,077
  • 4
  • 21
  • 55

1 Answers1

3

Use Typography.Variants, which meant to have subscript/ superscript style rendering. Ref.

MDSN example

enter image description here

<Paragraph FontFamily="Palatino Linotype">
  2<Run Typography.Variants="Superscript">3</Run>
  14<Run Typography.Variants="Superscript">th</Run>
</Paragraph>

enter image description here

<Paragraph FontFamily="Palatino Linotype">
  H<Run Typography.Variants="Subscript">2</Run>O
  Footnote<Run Typography.Variants="Subscript">4</Run>
</Paragraph>
S.N
  • 4,910
  • 5
  • 31
  • 51
  • I've tried this `Normal Text2334` but it does not work for me. Paragraph is not present in Visual Studio and I cannot add it via code in XAML. – FrancescoDS Jun 21 '13 at 13:53
  • Refer relevant namespace and in this case it is System.Windows.Documents (in PresentationFramework.dll). ref : http://msdn.microsoft.com/en-us/library/system.windows.documents.paragraph.aspx – S.N Jun 21 '13 at 14:13
  • Done, but IDE tells me that it is impossible to assing the specified value. – FrancescoDS Jun 21 '13 at 14:25
  • In the link of your last comment, there is no refer to namespace System.Windows.Documents in the example at bottom of page. – FrancescoDS Jun 21 '13 at 14:34
  • 1
    To resolve issue, I've used the BaselineAlignment directive in the XAML. Now I need to know how to use it in C#, because I need to write textblock with the following text: ag (g) with first 'g' as subscript...please help – FrancescoDS Jun 24 '13 at 14:28