This is a migrated thread and some comments may be shown as answers.

Paragraph spacing - RtfFormatProvider

2 Answers 173 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 16 Sep 2011, 10:07 PM
Hello,

I have a RadRichTextBox that the user can enter formatted text, and save it to the database to view again later.  I use richTextBox1.Document = rtfProvider.Import(formattedText) to populate the textbox, and  rtfProvider.Export(richTextBox1.Document) to get the text to save to the database.  This works just fine.

The problem I'm having is with paragraph line spacing.  Say the user changes the line spacing to single, and the spacing after to 0, then saves the text.  When it's loaded in the textbox again, the line spacing is single (correct), but the spacing after is 9.0 pt (incorrect).

Any ideas?
Thanks,
Justin

<telerik:RadRichTextBox DocumentInheritsDefaultStyleSettings="True"
     Height="140" HorizontalAlignment="Stretch" HorizontalScrollBarVisibility="Hidden"
     IsContextMenuEnabled="True" IsSelectionMiniToolBarEnabled="True"
     IsSpellCheckingEnabled="False" Name="richTextBox1" VerticalAlignment="Top"
     VerticalScrollBarVisibility="Hidden">
</telerik:RadRichTextBox>
// Loading Textbox
String formattedText = //retrieve from database
RtfFormatProvider provider = new RtfFormatProvider();
richTextBox1.Document = provider.Import(formattedText);
 
// Saving text
RtfFormatProvider provider = new RtfFormatProvider();
string formattedText = provider.Export(richTextBox1.Document);
// save formattedText to database

2 Answers, 1 is accepted

Sort by
0
Justin Lee
Top achievements
Rank 1
answered on 17 Sep 2011, 05:39 PM
Some more information...

- I now use databind to the richtextbox -- but I still have the same issue.
- I subscribed to the SetupDocument event, and set e.Document.ParagraphDefaultSpacingAfter = 0 -- but still have the issue
- If I use HtmlDataProvider, I do NOT have the issue.  But I would prefer to use RtfDataProvider.

Thanks,
Justin
void p_SetupDocument(object sender, Telerik.Windows.Documents.FormatProviders.SetupDocumentEventArgs e)
{
  e.Document.ParagraphDefaultSpacingAfter = 0;
}

<my1:RtfDataProvider x:Key="rtfProvider" SetupDocument="p_SetupDocument"
            RichTextBox="{Binding ElementName=radRichTextBox1}"
            Rtf="{Binding Descriptor, Mode=TwoWay}">
</my1:RtfDataProvider>
 
<telerik:RadRichTextBox DocumentInheritsDefaultStyleSettings="True"
Height="140"
IsSelectionMiniToolBarEnabled="True"
Name="radRichTextBox1" >
</telerik:RadRichTextBox>
0
Boby
Telerik team
answered on 21 Sep 2011, 04:18 PM
Hi Justin Lee,
We did not manage to reproduce the issue with a simple document. Could you please send us the problematic document exported as XAML, so we can investigate it further?
ParagraphDefaultSpacingAfter is used on creation of new paragraphs, and SetupDocument event is fired after the document is deserialized, thus the paragraphs' spacing after is not set. You can, however, use RadDocument.EnumerateChildrenOfType<Paragraph>() to get an enumerator of all the paragraphs in the document and  set their SpacingAfter property as needed.
As a general practice, we recommend using our native Xaml format, since with it no information is lost on export/import round-trip.

Don't hesitate to contact us if you have other questions.


All the best,
Boby
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Justin Lee
Top achievements
Rank 1
Boby
Telerik team
Share this question
or