Document Properties in WPF DOCX Editor
18 Aug 20263 minutes to read
WPF RichTexBox keep tracking the statistics about your documents. These statistics contains information about word count, paragraph count and pages count.
Word count
RichTextBox automatically counts the number of words in a document while you type. You can get the words count from 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, ElementName=richTextBoxAdv}" />int wordCount = richTextBoxAdv.WordCount;Dim wordCount As Integer = richTextBoxAdv.WordCountParagraph count
RichTextBox automatically counts the number of paragraphs in a document while you type. You can get the paragraph count from ParagraphCount property. The default value of this property is 0. Also, it ignores empty paragraphs.
The following sample code demonstrates how to get the total number of paragraphs in the document.
<TextBlock Text="{Binding Path=ParagraphCount, Mode=TwoWay, ElementName=richTextBoxAdv}" />int paragraphCount = richTextBoxAdv.ParagraphCount;Dim paragraphCount As Integer = richTextBoxAdv.ParagraphCountPage count
RichTextBox counts the number of pages in a document while you type. You can get the page count from PageCount property. The default value of this property is 0.
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 SubCurrent page number
The CurrentPageNumber property in the RichTextBox control returns the page number where the selection(cursor) is present.
The following sample code demonstrates how to get 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 SubNOTE
The above PageCount and CurrentPageNumber properties are not a dependency property. And it is not notifying for dynamic changes. So, get these properties value in
selection changed event.
NOTE
You can refer to our WPF RichTextBox feature tour page for its groundbreaking feature representations. You can also explore our WPF RichTextBox example to know how to render and configure the editing tool.