Document Properties in UWP DOCX Editor

18 Aug 20263 minutes to read

RichTexBox keep tracking the statistics about your documents. These statistics contains information about word count, paragraph count and pages count.

SfRichTextBoxAdv keeps track of statistics about your document. These statistics contain information about word count, paragraph count, and page count. The following sections describe each statistic and how to retrieve it.

Word count

SfRichTextBoxAdv automatically counts the number of words in a document while you type. You can get the word count from the WordCount property. The default value of this property is 0.

The following sample code demonstrates how to get the total number of words in the document.

<TextBlock Text="{Binding Path=WordCount, Mode=TwoWay}"  />
int wordCount = richTextBoxAdv.WordCount;
Dim wordCount As Integer = richTextBoxAdv.WordCount

Paragraph count

SfRichTextBoxAdv automatically counts the number of paragraphs in a document while you type. You can get the paragraph count from the ParagraphCount property. The default value of this property is 0. Empty paragraphs are ignored.

The following sample code demonstrates how to get the total number of paragraphs in the document.

<TextBlock x:Name="paragraphCount" Text="{Binding Path=ParagraphCount}" />
int paragraphCount = richTextBoxAdv.ParagraphCount;
Dim paragraphCount As Integer = richTextBoxAdv.ParagraphCount

Page count

SfRichTextBoxAdv counts the number of pages in a document while you type. You can get the page count from the PageCount property. The default value of this property is 0.

NOTE

PageCount is not a dependency property and does not raise change notifications. Read its value inside the SelectionChanged event, as shown below.

The following sample code demonstrates how to get the total number of pages in the document.

<TextBlock x:Name="pageCount" Grid.Row="0" />
<RichTextBoxAdv:SfRichTextBoxAdv Grid.Row="1" x:Name="richTextBoxAdv" SelectionChanged="RichTextBoxAdv_SelectionChanged" />
private void RichTextBoxAdv_SelectionChanged(object obj, SelectionChangedEventArgs args)
{
	pageCount.Text = richTextBoxAdv.PageCount.ToString();
}
Private Sub RichTextBoxAdv_SelectionChanged(ByVal obj As Object, ByVal args As SelectionChangedEventArgs)
pageCount.Text = richTextBoxAdv.PageCount.ToString()
End Sub

Current page number

The CurrentPageNumber property returns the page number where the selection (cursor) is present in the document.

NOTE

CurrentPageNumber is not a dependency property and does not raise change notifications. Read its value inside the SelectionChanged event, as shown below.

The following sample code demonstrates how to get the current page number in the document.

<TextBlock x:Name="currentPageNumber" Grid.Row="0" />
<RichTextBoxAdv:SfRichTextBoxAdv Grid.Row="1" x:Name="richTextBoxAdv" SelectionChanged="RichTextBoxAdv_SelectionChanged" />
private void RichTextBoxAdv_SelectionChanged(object obj, SelectionChangedEventArgs args)
{
	currentPageNumber.Text = richTextBoxAdv.CurrentPageNumber.ToString();
}
Private Sub RichTextBoxAdv_SelectionChanged(ByVal obj As Object, ByVal args As SelectionChangedEventArgs)
    currentPageNumber.Text = richTextBoxAdv.CurrentPageNumber.ToString()
End Sub

See also