I am developing a UWP app in which I use a RichEditBox control. I am trying to change the Linespacing(space between two lines) in my code. I have tried all the LineSpacingRule , but it is not reflecting in my UI. Here is my code
RichEditBox richedit = new RichEditBox();
richedit.FontSize = 14;
richedit.Style = Application.Current.Resources["RichEditBoxStyleForTextNote"] as Style;
richedit.Background = new SolidColorBrush(Colors.Transparent);
string rtf = HelperFunctions.ConvertHtmlToRtf(html); //HelperFunctions.HTMLtoRTF(html);
richedit.Document.SetText(TextSetOptions.FormatRtf, rtf);
richedit.IsReadOnly = true;
richedit.Document.GetDefaultParagraphFormat().SetLineSpacing(LineSpacingRule.OneAndHalf, 0f);
I have tried all LineSpacingRule types, but couldn't see any increase in line space.
Can anyone help me to increase the linespace .
Thanks, Noorul.
The issue here is that you are changing the LineSpacing of the control but the control displays a document which contains it's own styling and display information for what is shown.
The easiest way to set the LineSpacing is to get the current formatting and then adjust the line spacing as desired.
Like this:
var format = richedit.Document.GetDefaultParagraphFormat();
format.SetLineSpacing(LineSpacingRule.AtLeast, 20);
richedit.Document.SetDefaultParagraphFormat(format);