Search code examples
c#uwptextboxricheditbox

Get Text From RichEditBox


I have a RichEditBox where the user can write their own text, like below:

<RichEditBox
                            x:Name="jawabBox"
                            Grid.Row="0"
                            FontSize="21"
                            FontWeight="SemiBold"
                            HorizontalAlignment="Stretch"
                            VerticalAlignment="Stretch"
                            Background="#FFDBDBDB"
                            Foreground="Black"
                            CornerRadius="15,15,15,15" />

How to get the text that has been written by the user? Or how can the user write text into a textbox with multiple lines, other than using RichEditBox?


Solution

  • As @Flydog57 mentioned, you could get the text via the ITextDocument.GetText() Method. It requires a TextGetOptions Enum as parameter and a string as output value.

    You could use it like this:

     string value = string.Empty;
            jawabBox.Document.GetText(Windows.UI.Text.TextGetOptions.AdjustCrlf, out value);