3

I'm building a Windows Phone 8.1/Windows 8.1 app (WinRT) and I'm using a RichEditBox control. Every time I add text to it, the cursor goes to the beginning of the text and I can't find a way to move it to the end of the text.

I've build two methods to Set and Add text:

public static void SetText(this RichEditBox e, string text)
{
    e.Document.SetText(Windows.UI.Text.TextSetOptions.None, text); 
}

public static string GetText(this RichEditBox e)
{
   string value;
   e.Document.GetText(Windows.UI.Text.TextGetOptions.AdjustCrlf, out value); 
   return  value;
 }

And I'm using this code to add text to it:

StatusBox.SetText(StatusBox.GetText() +
                                  texttoadd);

Now, how can I move the cursor to the end of the text?

Alessandro S.
  • 93
  • 2
  • 7

1 Answers1

2

By manipulating the Selection property in the Document property of the RichEditBox

var newPos = StatusBox.GetText().length-1;
StatusBox.Document.Selection.SetRange(newPos,newPos)
StatusBox.Focus(FocusState.Keyboard);
Xi Sigma
  • 2,292
  • 2
  • 13
  • 16