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

Custom field doesn't inherit formats

1 Answer 11 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Tomas asked on 03 Aug 2018, 10:36 AM

Hi

I've created a new custom field which write in a span some text(with some carriage returns)

When I put it inside the RTB it is not formatted with the same font family, font size, etc as the sibling elements 
I doesn't inherit the formats the the sibling elements already have
If I put a docvariable all is fine

 

thanks in advance

1 Answer, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 08 Aug 2018, 06:33 AM
Hi Tomas,

Could you please ensure that the current span style is transferred to the fragment of the field that is being inserted? You can obtain this information from the EvaluationContext property of the document. This property holds information about the RadDocument instance, from which you can get the current span and extract its styling. Here is an example implementation of the GetResultFragment() method that should be implemented for the custom field:
protected override DocumentFragment GetResultFragment()
{
    int totalPageCount = 1;
    int totalPageInCurrentSection = 1;
    int currentPageInCurrentSection = 1;
 
    if (this.EvaluationContext != null)
    {
        totalPageCount = this.GetTotalPageCount();
 
        LayoutBox box = this.EvaluationContext.AssociatedLayoutBoxInMainDocument ?? this.FieldStart.FirstLayoutBox;
 
        currentPageInCurrentSection = this.GetCurrentPageFromSectionPages(box);
        totalPageInCurrentSection = this.GetPageCountInSection(box);
    }
 
    Span currentSpan = this.EvaluationContext.Document.CaretPosition.GetCurrentSpan();
    Span spanToInsert = new Span(
        string.Format("Total pages in the document: {0}. Pages in current section: {1} / {2}",
                        totalPageCount, currentPageInCurrentSection, totalPageInCurrentSection));
    spanToInsert.CopyPropertiesFrom(currentSpan);
 
    return DocumentFragment.CreateFromInline(spanToInsert);
}

Hope this is helpful.

Regards,
Tanya
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextBox
Asked by
Tomas
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Share this question
or