Approved
Last Updated: 05 Apr 2018 14:31 by ADMIN
ADMIN
Mihail
Created on: 21 Aug 2017 07:52
Category: RichTextBox
Type: Feature Request
1
RichTextBox: Allow field inserted in child document (header/footer) to access properties from the main document
Allow the custom fields inserted in a child document, like header/footer/comment etc, to access properties from the main document of RadRichTextBox.
2 comments
ADMIN
Tanya
Posted on: 05 Apr 2018 14:31
Hi,

The feedback portal is used to discuss particular issues or requests for new functionalities. Please, post any technical questions you might have in the support system so the support team can handle them appropriately. Thank you for understanding.

Regards,
Tanya
①Dr Mostafa
Posted on: 21 Aug 2017 20:58
Hi every body ....

I use RadRichTextBox in the following manner: first page is used (by the user) as a cover letter so that it is not included within the total count of pages. Footer of every page except first page should display page number x from y, where x is the current page number (after the first page), and y is the total number of pages minus one (the first page).

I could achieve the first value of the formatted footer using CodeBasedField, but unfortunately I couldn't modify the value returned by NumPagesField.

My question is how to modify value returned by NumPagesField so that I can display total number of pages minus one. Below there is an attachment of an image to show my requirement.

The following is my code snippet used in creating the custom footer:


Public Function FirstTemplate() As RadDocument
Dim section As New Section()
 section.HasDifferentFirstPageHeaderFooter = True
section.Footers.[Default] = New Footer With {.Body = ReportFooter()}
End Function
 
Private Function ReportFooter() As RadDocument
    Dim footerDoc As New RadDocument
Dim footerSection As New Section
            Dim footerParagraph As New Paragraph
            Dim footerDocumentEditor As New RadDocumentEditor(footerDoc)
 
            footerParagraph.TextAlignment = RadTextAlignment.Center
            footerDoc.Sections.Add(footerSection)
            footerSection.Blocks.Add(footerParagraph)
            footerDocumentEditor.InsertField(New FormattedPageNumber, FieldDisplayMode.Result)
             
            Return footerDoc
        End Function
 
Public Class FormattedPageNumber
        Inherits CodeBasedField
        Public Shared ReadOnly FieldType As String = "FormattedPageNUM"
 
        Shared Sub New()
            CodeBasedFieldFactory.RegisterFieldType(FormattedPageNumber.FieldType, Function()
                                                                                       Return New FormattedPageNumber()
                                                                                   End Function)
        End Sub
 
        Public Overrides ReadOnly Property FieldTypeName() As String
            Get
                Return FormattedPageNumber.FieldType
            End Get
        End Property
 
        
Protected Overrides Function GetResultFragment() As DocumentFragment
            Dim pageNumber As Integer = 0
            Dim pagesCount As Integer = 0
 
            If Me.Document IsNot Nothing Then
                Dim position As New DocumentPosition(Me.Document)
                position.MoveToStartOfDocumentElement(Me.FieldStart)
                Dim sectionBox As SectionLayoutBox = position.GetCurrentSectionBox()
                 
                pageNumber = sectionBox.PageNumber
                pagesCount = DocumentStructureCollection.GetChildrenCount(Me.Document.DocumentLayoutBox)
            End If
 
            Dim resultString As String = "Page " & pageNumber - 1 & " From " & pagesCount -1
 
            Return MyBase.CreateFragmentFromText(resultString)
        End Function
 
        Public Overrides Function CreateInstance() As Field
            Return New FormattedPageNumber()
        End Function
    End Class

In code above; the problem is pagesCount always returns zero. 
As I could understand, this behavior was the result of implementation being used within the footer, and hence telerik team added NumPagesField, so that it could be used within the footer. But how could I modify it, or is their another way to access properties of parent document from footer????
Attached Files: