Line Spacing after Enter in RadRichTextBox

2 Answers 25 Views
RichTextBox
Ramesh
Top achievements
Rank 1
Iron
Ramesh asked on 27 May 2021, 07:09 PM | edited on 28 May 2021, 02:41 PM

I did all I can Still I cannot take away the line spacing after hitting  "Enter", I could not get it working  (looks like the DocumentInheritsDefaultStyleSettings  is interfering?)

I have uploaded a sample project (that tells the behavior) as well.

 

Please find the code I used below.

                                <telerik:RadRichTextBox x:Name="custNotesRichTextBox"
                                                        Grid.Row="0"
                                                        DocumentInheritsDefaultStyleSettings="True"                                                     
                                                        AcceptsTab="True"
                                                        AcceptsReturn="True"                                                         
                                                        ScrollViewer.VerticalScrollBarVisibility="Auto"
                                                        HorizontalScrollBarVisibility="Hidden"                                                        
                                                        IsSpellCheckingEnabled="True"
                                                        Language="en-US"
                                                        IsContextMenuEnabled="True"                                                        
                                                        Margin="0"
                                                        VerticalScrollBarVisibility="Hidden">
                                    <telerik:RadRichTextBox.Document>
                                    <telerik:RadDocument LineSpacing="0" LineSpacingType="AtLeast" ParagraphDefaultSpacingAfter="0" ParagraphDefaultSpacingBefore="0" >
                                        <telerik:Section>
                                                <telerik:Paragraph LineSpacing="0" LineSpacingType="AtLeast" SpacingBefore="0" SpacingAfter="0" AutomaticSpacingBefore="False" AutomaticSpacingAfter="False" >
                                                <telerik:Span  Text=" "/>
                                            </telerik:Paragraph>
                                        </telerik:Section>
                                    </telerik:RadDocument>
                                    </telerik:RadRichTextBox.Document>
                                    </telerik:RadRichTextBox>
Ramesh
Top achievements
Rank 1
Iron
commented on 27 May 2021, 09:07 PM | edited

This question is for UI for WPF. please change the forum
Dimitar
Telerik team
commented on 31 May 2021, 06:41 AM

I have changed the forum.

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 02 Jun 2021, 09:24 AM

Hi Ramesh,

When the document is changed the styles are reset as well, so are the settings set at design time. You will need to change the normal style each time the document is changed. For example, you can use the DocumentChanged event and set the styles there:

public MainWindow()
{
    InitializeComponent();
    radRichTextBox.DocumentChanged += RadRichTextBox_DocumentChanged;
}

private void RadRichTextBox_DocumentChanged(object sender, EventArgs e)
{
    StyleDefinition normalStyle = this.radRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.NormalStyleName];
    normalStyle.ParagraphProperties.SpacingAfter = 0;
    normalStyle.ParagraphProperties.SpacingBefore = 0;
    normalStyle.ParagraphProperties.AutomaticSpacingAfter = false;
    normalStyle.ParagraphProperties.AutomaticSpacingBefore = false;
    normalStyle.ParagraphProperties.LineSpacing = 0;
    normalStyle.ParagraphProperties.LineSpacingType = LineSpacingType.AtLeast;
}

Let me know if I can assist you further.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Ramesh
Top achievements
Rank 1
Iron
commented on 02 Jun 2021, 07:55 PM

Hi Dimitar, this worked well! Thanks!
0
Dimitar
Telerik team
answered on 31 May 2021, 06:41 AM

Hi Ramesh,

You need to set the SpacingAfter property to 0. Here is how you can get the normal style and set this property: 

StyleDefinition normalStyle = this.custNotesRichTextBox.Document.StyleRepository[RadDocumentDefaultStyles.NormalStyleName]; 
normalStyle.ParagraphProperties.SpacingAfter = 0; 

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ramesh
Top achievements
Rank 1
Iron
commented on 01 Jun 2021, 07:49 PM

HI Dimitar, Thanks that worked, after adding few more lines to it, as below.

normalStyle.ParagraphProperties.SpacingAfter = 0;
normalStyle.ParagraphProperties.SpacingBefore = 0;
normalStyle.ParagraphProperties.AutomaticSpacingAfter = false;
normalStyle.ParagraphProperties.AutomaticSpacingBefore = false;
normalStyle.ParagraphProperties.LineSpacing = 0;
normalStyle.ParagraphProperties.LineSpacingType = LineSpacingType.AtLeast

But am curious why it didn't take the setting from the designer, and requiring us to manipulate the normal style is a question.
Ramesh
Top achievements
Rank 1
Iron
commented on 02 Jun 2021, 02:50 AM

1) Hi Dimitar, When I try to bind the text from the code behind, again I get spacing. How Can avoid spacing when I bind text to the richtext control from code behind. Please note am binding using the MVVM pattern.

2)Also, the above code sometimes work and the next time , when I launch the textbox, from a different item in the grid, the style is not reflected. Not sure why can you explain.
Tags
RichTextBox
Asked by
Ramesh
Top achievements
Rank 1
Iron
Answers by
Dimitar
Telerik team
Share this question
or