Click here to Skip to main content
15,905,419 members
Please Sign up or sign in to vote.
1.80/5 (2 votes)
See more:
How to use Subscript and superscript from code behind in windows 8 metro app
Posted

1 solution

Try something like this (the point is BaselineAlignment.Superscript / BaselineAlignment.Subscript):

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SimpleBaseline
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        texto anxn;
        public MainWindow()
        {
            InitializeComponent();
            anxn = new texto();
            anxn.T("a").L("n").T("x").U("n");
            FlowDocScroll.Document= new FlowDocument(anxn.GetPara);
        }
    }
    internal class texto
    {
        Paragraph q;
        internal texto()
        {
            q = new Paragraph();
        }
        internal Paragraph GetPara
        {
            get { return q; }
        }
        internal texto T(string data)
        {
            Span s = new Span();
            s.BaselineAlignment = BaselineAlignment.Center;
            s.Inlines.Add(data);
            q.Inlines.Add(s);
            return this;
        }
        internal texto U(string dataInSuperScript)
        {
            Span s = new Span();
            s.BaselineAlignment = BaselineAlignment.Superscript;
            s.Inlines.Add(dataInSuperScript);
            q.Inlines.Add(s);
            return this;
        }
        internal texto L(string dataInSubscript)
        {
            Span s = new Span();
            s.BaselineAlignment = BaselineAlignment.Subscript;
            s.Inlines.Add(dataInSubscript);
            q.Inlines.Add(s);
            return this;
        }
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900