RadRichTextBox - LineSpacing, Font Family, Font Size default style ignored

0 Answers 10 Views
RichTextBox
Patrick
Top achievements
Rank 1
Iron
Iron
Iron
Patrick asked on 17 May 2024, 04:11 PM
I have a telerik radRichTextbox that I need to set some defaults on for all areas that it is dynamically generated but nothing I am doing is working.

Here is my XAML set up below.
        <telerik:HtmlDataProvider RichTextBox="{Binding ElementName=radRichTextBox}" Html="{Binding MyRichText, Mode=TwoWay, NotifyOnValidationError=true, TargetNullValue='', ValidatesOnExceptions=true}">
            <telerik:HtmlDataProvider.FormatProvider>
                <telerik:HtmlFormatProvider>
                    <telerik:HtmlFormatProvider.ExportSettings>
                        <telerik:HtmlExportSettings DocumentExportLevel="Fragment"
ImageExportMode="AutomaticInline"
StyleRepositoryExportMode="DontExportStyles"
StylesExportMode="Inline"
ExportEmptyDocumentAsEmptyString="True"      
/>
                    </telerik:HtmlFormatProvider.ExportSettings>
                </telerik:HtmlFormatProvider>
            </telerik:HtmlDataProvider.FormatProvider>
        </telerik:HtmlDataProvider>

<telerik:RadRichTextBox x:Name="radRichTextBox" DocumentInheritsDefaultStyleSettings="True" Foreground="black" FontFamily="Times New Roman" FontSize="12"   Padding="10">
</telerik:RadRichTextBox>


What is the proper way to default to SINGLE line spacing and fontsize 12 with font family of Times New Roman?

Obviously the user should be able to change if they wish but I need it to atleast default initially to these values.
Dimitar
Telerik team
commented on 20 May 2024, 08:55 AM

Hi Patrick, 

Your approach is correct, however, the documents are usually caring these settings as well and this will override the local ones. To achieve this you can change the font after the document is loaded: 

private void RadRichTextBox_DocumentChanged(object sender, EventArgs e)
{
    this.radRichTextBox.Document.Selection.SelectAll();
    this.radRichTextBox.ActiveDocumentEditor.ChangeFontFamily(new FontFamily("Consolas"));
    this.radRichTextBox.ActiveDocumentEditor.ChangeFontSize(20);
    this.radRichTextBox.Document.Selection.Clear();
}

Patrick
Top achievements
Rank 1
Iron
Iron
Iron
commented on 20 May 2024, 05:00 PM

This will handle the font family, but still doesn't change the font size. Line spacing is still double spaced and this is happening on documentChanged.

Really just need it to happen on the initial load. Once the user modifies from the default, I don't want to change it automatically for them.
Dimitar
Telerik team
commented on 21 May 2024, 11:15 AM

Hi Patrick, 

I am not sure why this is not working on your side. 

Would it be possible to create a sample project that shows your exact case and send it to me? This will give me a better understanding and I will be able to investigate this.

Thank you in advance for your patience and cooperation. 

Patrick
Top achievements
Rank 1
Iron
Iron
Iron
commented on 21 May 2024, 05:23 PM

Hey Dimitar, I don't think I can get my exact process into a sample project in a timely manner and without breaking some rules from my organization. I will play around with it more and see what I can do. Do you have any tips for making it single space? Looks like you show how to change font size and font family. What about the line spacing? It should all be single space.
Dimitar
Telerik team
commented on 22 May 2024, 05:01 AM

Hi Patrick, 

You can use the following methods for this:

this.radRichTextBox.ActiveDocumentEditor.ChangeParagraphSpacingAfter(0);
this.radRichTextBox.ActiveDocumentEditor.ChangeParagraphSpacingBefore(0);
this.radRichTextBox.ActiveDocumentEditor.ChangeParagraphLineSpacing(0, LineSpacingType.Exact);

No answers yet. Maybe you can help?

Tags
RichTextBox
Asked by
Patrick
Top achievements
Rank 1
Iron
Iron
Iron
Share this question
or