We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Reusing formatting styles for ParagraphAdv instances

Hello,

I'm currently kind of stuck with one problem with paragraph styling with SfRichTextBoxAdv component. To put it simply, I'd like to create few text format templates that could be applied to a paragraphs (and only entire paragraphs) by a user. So let's say one of those templates would be "italics, left margin 20, Arial, 12pt", second would be "bold, left margin 10, Arial, 10pt, red background" etc. and the document would have number of paragraphs with those formattings.

I've tried to create instances of CharacterFormat class and then on key press do:

rtb.Selection.Start.Paragraph.CharacterFormat = my_template;

but it does absolultely nothing. I've also tried using selections, but that was a mess; I lose information about where user originally was in the text, and I couldn't even use preinstantiated CharacterFormats, as rtf.Selection.CharacterFormat property is apparently read-only.

My current solution is:

foreach (var inline in rtb.Document.DocumentStart.Paragraph.Inlines.AsEnumerable())
     (inline as SpanAdv).CharacterFormat.FontColor = my_color; // repeat similar lines for every property

which is pretty terrible solution imho, as I still can't use preinstantiated CharacterFormats - simply writing (inline as SpanAdv).CharacterFormat = my_template; doesn't work. I have to go through every property and set each individually every time.

When I worked with standard WPF richtexhtbox component, I'd just use styles, with setter and stuff, load them using FindResource method and apply them with:

rtb.CaretPosition.Paragraph.Style = my_style;

and it worked like a charm. How can I achieve this with SfRichTextBoxAdv and ParagraphAdv, please?

Also, one more question - is it possible to uniquely identify user created paragraphs with some dynamic ID (that would stay the same across multiple document loads) or store aditional custom information with them?

Thank you,
have a nice day

1 Reply

RT Ramya Thirugnanam Syncfusion Team April 9, 2019 11:54 AM UTC

Hi Jan, 
Thanks for contacting Syncfusion support. 
Query 
Response 
I've tried to create instances of CharacterFormat class and then on key press do: 
 
rtb.Selection.Start.Paragraph.CharacterFormat = my_template; 
 
The given code example will not change the paragraph style entirely. This will apply the character format to the paragraph intent alone(as shown in the image below). 
 
 
Character format is applied as red and font size 12. 
 
 
When I worked with standard WPF richtexhtbox component, I'd just use styles, with setter and stuff, load them using FindResource method and apply them with: 
 
rtb.CaretPosition.Paragraph.Style = my_style; 
 
and it worked like a charm. How can I achieve this with SfRichTextBoxAdv and ParagraphAdv, please? 
 
Currently, we do not have support for applying styles to the paragraph in our SfRichTextBoxAdv. We have road map for this, and we are currently implementing this feature. This will be available in our Volume 2 release which is expected to be available in the month of June 2019. 
 
Now, you can now track the status of your request, review the proposed resolution timeline, and contact us for any further inquiries through below link. 
 
 
Workaround: 
Yes, as of now we could achieve only by using the way you have used it. 
 
CharacterFormat my_template = new CharacterFormat();
my_template.Italic = true;
my_template.FontSize = 12;
my_template.FontFamily =new FontFamily("Arial");
 
 
foreach (var inline in richTextBoxAdv.Document.DocumentStart.Paragraph.Inlines.AsEnumerable()) 
    (inline as SpanAdv).CharacterFormat = my_template; 
 
 
 is it possible to uniquely identify user created paragraphs with some dynamic ID (that would stay the same across multiple document loads) or store aditional custom information with them? 
This is not possible with in our SfRichTextBoxAdv. Could you please provide us screenshot or description about your use case for this feature? So that, we could check and share some possible solutions if any. 
 
 
 
 
Regards,  
Ramya T 


Loader.
Live Chat Icon For mobile
Up arrow icon