What is the best way to detect if a WPF RichTextBox/FlowDocument is empty?
The following works if only text is present in the document. Not if it contains UIElement’s
new TextRange(Document.ContentStart, Document.ContentEnd).IsEmpty
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could compare the pointers, which is not all too reliable:
This evaluates to
2if the RTB is loaded, and4if content has been entered and removed again.If the RTB is completely cleared out e.g. via
select all -> deletethe value will be0.In the Silverlight reference on MSDN another method is found which can be adapted and improved to: