string.IsNullOrWhiteSpace
should actually work. Try this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
string s = ConvertRichTextBoxContentsToString(rtb);
if (string.IsNullOrWhiteSpace(s))
{
MessageBox.Show("empty!");
}
}
}
<RichTextBox x:Name="rtb" />
This works as well:
string s = ConvertRichTextBoxContentsToString(rtb);
if(s == "\r\n")
{
MessageBox.Show("empty!");
}
And Equals as well:
string s = ConvertRichTextBoxContentsToString(rtb);
if (s.Equals("\r\n"))
{
MessageBox.Show("empty!");
}
If you don't see the MessageBox the RichTextBox is not truly empty. You may want to read this:
Detect if a RichTextBox is empty
If content has been entered and removed the difference between the start and end pointers is 4. You may try to use the following method from above to determine whether the RichTextBox is empty:
public bool IsRichTextBoxEmpty(RichTextBox rtb)
{
if (rtb.Document.Blocks.Count == 0) return true;
TextPointer startPointer = rtb.Document.ContentStart.GetNextInsertionPosition(LogicalDirection.Forward);
TextPointer endPointer = rtb.Document.ContentEnd.GetNextInsertionPosition(LogicalDirection.Backward);
return startPointer.CompareTo(endPointer) == 0;
}