locked
Changing the line spacing of a TextBox in C#/WinRT

    Question

  • Is there any way to change the line spacing or line height of a TextBox in a C# WinRT app?

    It's possible to do this with the TextBox element in WPF through a XAML attribute like so:

    
    
    <TextBox TextBlock.LineHeight="10" TextBlock.LineStackingStrategy="BlockLineHeight" /> 
    

    Silverlight has a LineHeight attribute that can be directly applied to a TextBox element.

    WinRT doesn't allow either of these.

    In WinRT, it is possible to change the line height of the text in a RichEditBox like so (where EditorBox is a RichEditBox):

    Windows.UI.Text.ITextParagraphFormat LineHeight = EditorBox.Document.GetDefaultParagraphFormat();
    LineHeight.SetLineSpacing(Windows.UI.Text.LineSpacingRule.OneAndHalf, 1);
    

    But this doesn't really help me as I want to change the line height of a TextBox element. Is there any way that I can do this?




    Saturday, June 7, 2014 12:32 PM

Answers

  • Not with the TextBox. If you need richer editable text handling then you'll need to switch to a RichEditBox.

    --Rob

    Saturday, June 7, 2014 8:02 PM
    Owner
  • While it isn't a particularly good solution to the problem, I was able to achieve what I wanted by editing the ascent and descent metrics of a custom font file and then using that font in my project.

    I do hope that a future version of WinRT will restore the ability to set the LineHeight property in XAML rather than having to resort to methods like this though.

    Sunday, June 8, 2014 10:51 AM

All replies

  • Not with the TextBox. If you need richer editable text handling then you'll need to switch to a RichEditBox.

    --Rob

    Saturday, June 7, 2014 8:02 PM
    Owner
  • While it isn't a particularly good solution to the problem, I was able to achieve what I wanted by editing the ascent and descent metrics of a custom font file and then using that font in my project.

    I do hope that a future version of WinRT will restore the ability to set the LineHeight property in XAML rather than having to resort to methods like this though.

    Sunday, June 8, 2014 10:51 AM