Hello,
How to get/calculate height of RichTextDocument (content height)?
Regards
Hello Tg,
I have been investigating into your requirement in this case, and there does not currently appear to be anything exposed that returns the height of the Content of the RichTextDocument. There are a couple of options that you might be able to use in this case, and I will detail them below:
The first option is only really an option if the XamRichTextEditor being measured in this case is scrollable as this will cause the vertical scroll-bar to show up, and walking through the visual tree of the XamRichTextEditor can help you get an approximate height of the content of your document. The Maximum property of the vertical scroll bar is a double offset to the "Text Area" of the XamRichTextEditor. As such, you can approximate the height of the content of your document by utilizing the Infragistics.Windows.Utilities class to walk the visual tree of the editor, get these elements, and then add the ActualHeight of the text area to the Maximum of the vertical scroll bar. The code for this could look like the following:
var textArea = Utilities.GetDescendantFromName(editor, "TextArea") as RichDocumentViewTextArea; var verticalScrollArea = Utilities.GetDescendantFromName(editor, "VerticalScrollBarArea") as RichDocumentViewScrollBarArea;var verticalScrollBar = Utilities.GetDescendantFromName(verticalScrollArea, "ScrollBar") as ScrollBar; double contentHeight = textArea.ActualHeight + verticalScrollBar.Maximum;
var verticalScrollArea = Utilities.GetDescendantFromName(editor, "VerticalScrollBarArea") as RichDocumentViewScrollBarArea;var verticalScrollBar = Utilities.GetDescendantFromName(verticalScrollArea, "ScrollBar") as ScrollBar;
double contentHeight = textArea.ActualHeight + verticalScrollBar.Maximum;
Again, though, this only really works if your RichDocumentViewTextArea is scrollable. Otherwise, you just get the Height of the text area.
The second option is not ideal, as it would require you to recursively loop through the nodes that exist on your RichTextDocument and manually measure the text values inside. This could be done using the FormattedText class, but this unfortunately will not work for tables and other content that might be placed in the editor. You will also need to determine the number of lines that make up a set of nodes as well by basing the length of your nodes on the ActualWidth of the "text area" above. Again, this is not ideal, as it would potentially be very, very complex.
I am rather curious as to what purpose you need the height of the Content of the XamRichTextEditor for, as there might be a far better way of achieving what you are looking to do. Would it be possible for you to please provide this information?
If you would like to see a publically exposed property that returns the height of the Content in the XamRichTextEditor, I would recommend suggesting a new product idea for it by e-mailing ideas@infragistics.com. This will place you in direct communication with our product management teams who plan and prioritize upcoming features and development based on community and user feedback.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Hi,
We have reporting documents in our software which consist of multiple different controls (graphics, text etc..). We need to be able to measure all of these components before rendering them, so we can calculate the layout correctly. One of these components is the RichTextEditor, so we would need the height of the RichTextDocument so we can reserve just enough space for it.