Search code examples
c#uwpricheditbox

Set RichEditBox to empty


I have a richeditbox whose contents can be filled in by the user XAML:

<RichEditBox
      x:Name="jawabBox"
      FontWeight="SemiBold"
      HorizontalAlignment="Stretch"
      VerticalAlignment="Stretch"
      Background="#FFDFF6EE"
      Foreground="Black"
      CornerRadius="15,15,15,15" BorderBrush="{x:Null}" PlaceholderText="Jawaban"/>

I have a problem, namely: when the user has filled in the richeditbox, then clicks the next button, then I want to set the next richeditbox to empty, but it doesn't work.

Code when setting richeditbox to empty:

string textValue = string.Empty;
jawabBox.Document.GetText(TextGetOptions.AdjustCrlf, out textValue);

How to handle it?


Solution

  • It is recommended to use ITextDocument.SetText to set your richeditbox to empty.

    jawabBox.Document.SetText(TextSetOptions.None, string.Empty);