locked
SubScript and SuperScript in TextBlock RRS feed

  • Question

  • Hello,

     Is it possible to have these two ?

     

    Thanks

    Friday, January 9, 2009 6:42 AM

Answers

  • I'll try to give you a more complete answer for anyone googling this issue.

    Silverlight_kid was right in saying that sub/superscript in Silverlight is limited due to not supporting "BaseLineAlignment", but not in saying that it is then only possible with positioning. 

    You can achieve limited sub/superscript without positioning (limited to numbers and basic arithmetic) by using unicode letters. Hopefully, Silverlight will be updated in the near future to support this. Until then, I will be working on getting the positioning working correctly and easily. I have to for a project anyway and I might as well release the code if I can manage it.

    Other Notes:

    1. Silverlight (more accurately, the Portable User Interface font that Silverlight defaults to) only supports versions of Unicode through Unicode 2.1, not the latest version (5.2).

    2. To construct a string with unicode characters, you need a backslash followed by an 'x' followed by the four digit hex code for that character. Only characters in the Basic Multilingual Plane (0000-FFFF) are supported. See examples.

    string water = "H" + "\x2082" + "O"; // You can split the string up if you want. 
    
    string ammonia = "NH\x2083"; // Or not split it.
    
    string energy = "e=mc\x00B2"; // Most well-known, poorly understood equation.
    
    string PythagoreanTheorem = "a\x00B2+b\x00B2=c\x00B2"; \\ Also well-known.

    3. Character reference.

    Superscript:

    0 : U+2070

    1 : U+00B9

    2 : U+00B2

    3 : U+00B3

    4-9 : U+2074-2079

    + : U+207A

    - : U+207B

    = : U+207C

    ( : U+207D

    ) : U+207E

    n : U+207F

    Subscript

    0-9 : U+2080-2089

    + : U+208A

    - : U+208B

    = : U+208C

    ( : U+208D

    ) : U+208E

    Tuesday, October 19, 2010 11:48 AM
  • Silverlight not support "BaseLineAlignment"

    so answer is you cant acheive  sub and superscript with out positioning

     

    Sunday, January 11, 2009 10:00 AM

All replies

  • Hi,

    I guess you can't do that directly but what you can do is:

    Go to  - Start > Programs > Accessories > Systems Tools > Character Map

    Type the subscript / superscript or the text you wanted & copy that as Text in silverlight textbox

    It works fine!

     

    Thanks & Regards,

    Mahesh Panhale 

     

    Friday, January 9, 2009 8:05 AM
  •  I don't want to use it on a TextBox but I want to use it in a TextBLOCK to diplay it...

    Unfortunately  I've just efound that it's because of the fact that the BaseLine property from WPF is not accessible in Silverlight...

    Friday, January 9, 2009 8:38 AM
  •  Hi,

    Im tried that one, but am not find out any correct way. Some posts are say, use two text blocks and one is main part and another one is super or sub. That second textblock is set to position(margin), up or down of first text. But its not correct way, becoz if we dynamically find out any data, its very difficult.(for ex, datagrid).

     

    Thanks

    Friday, January 9, 2009 9:19 AM
  • Silverlight not support "BaseLineAlignment"

    so answer is you cant acheive  sub and superscript with out positioning

     

    Sunday, January 11, 2009 10:00 AM
  • I'll try to give you a more complete answer for anyone googling this issue.

    Silverlight_kid was right in saying that sub/superscript in Silverlight is limited due to not supporting "BaseLineAlignment", but not in saying that it is then only possible with positioning. 

    You can achieve limited sub/superscript without positioning (limited to numbers and basic arithmetic) by using unicode letters. Hopefully, Silverlight will be updated in the near future to support this. Until then, I will be working on getting the positioning working correctly and easily. I have to for a project anyway and I might as well release the code if I can manage it.

    Other Notes:

    1. Silverlight (more accurately, the Portable User Interface font that Silverlight defaults to) only supports versions of Unicode through Unicode 2.1, not the latest version (5.2).

    2. To construct a string with unicode characters, you need a backslash followed by an 'x' followed by the four digit hex code for that character. Only characters in the Basic Multilingual Plane (0000-FFFF) are supported. See examples.

    string water = "H" + "\x2082" + "O"; // You can split the string up if you want. 
    
    string ammonia = "NH\x2083"; // Or not split it.
    
    string energy = "e=mc\x00B2"; // Most well-known, poorly understood equation.
    
    string PythagoreanTheorem = "a\x00B2+b\x00B2=c\x00B2"; \\ Also well-known.

    3. Character reference.

    Superscript:

    0 : U+2070

    1 : U+00B9

    2 : U+00B2

    3 : U+00B3

    4-9 : U+2074-2079

    + : U+207A

    - : U+207B

    = : U+207C

    ( : U+207D

    ) : U+207E

    n : U+207F

    Subscript

    0-9 : U+2080-2089

    + : U+208A

    - : U+208B

    = : U+208C

    ( : U+208D

    ) : U+208E

    Tuesday, October 19, 2010 11:48 AM
  • You're the Man lordcheeto !!!


    Thank you very much for reviving this topic and providing a great answer !!!!!


    However, still haven't found a way to use it directly from XAML but I can live with this solution


    Thanks again, Cheers,

    Tuesday, October 19, 2010 12:20 PM
  • However, still haven't found a way to use it directly from XAML but I can live with this solution


    I know the question is a little old, but I thought I'd add a comment anyway. You can use unicode letters in xaml like you would use any other special characters in xml:

    '>': > or b

    "m³": "m³"

    "H₂O": "H₂O"

    "eⁿ": "eⁿ"

    You probably get the drift.

    I haven't tried all the codes posted by lordcheeto, but they should work.

    Tuesday, May 31, 2011 5:44 AM
  • I hate to reactivate this thread, but I seem to be running into an issue with the proposed solution.

    If you print out the string "987123456" with using the unicode characters described above, 9, 8, 4, 5, 6 come out in a very small, almost unreadable, font size and 1,2, and 3 are in a larger font size.  Has anyone else run into this?  If so, is there a way to get them all to be displayed at the font size used in 1, 2, and 3?

     

    Jerry

    PS.  I solved this issue.  It appears that the sizing is font specific.  I believe the default font is "Portable User Interface" and has the sizing issue.  Changing the font to "Lucida Sans Unicode" cures the problem.

    Thursday, August 18, 2011 10:47 AM