How to control visibility of cursor in RichEditBox while editing in Windows store app using C#? RRS feed

  • Question

  • Hello,

    Could any one please help me with couple of cursor visibility issue with RichEditBox in Windows store app?

    1.  Basically, I am trying to place the cursor at the end of the text in RichEditBox when a user taps on it.  Currently by default, the RichEditBox displays the cursor at the beginning and when the user starts typing it is adding text at the end.  Is there any way to change the default behavior?  I tried using ITextDocument.Selection.EndKey, but the cursor visibility is still getting displayed at the start of the text box.

    2.  One other problem, I am facing is, when the user taps on the RichEditBox for the first time, the cursor is not visible but it is letting user to enter the text into it.  Cursor is visible only when the user double taps on the RichEditBox.  Could any one please help to change this default behavior as well?

    Thanks for the help.



    Thursday, January 9, 2014 12:25 AM

All replies

  • You cannot directly control the cursor visibility. That is all handled internal to the RichEditBox.

    You can control where the cursor is by setting the selection (as you're doing), but you need to make sure that your timing is correct. You don't say when exactly you are setting the selection, and I suspect the control is resetting the selection based on where the user touched afterwards. If so you'll have more success moving the selection point a bit later. I would be careful about this though, as the user may be frustrated if she tries to select a word to edit and the app yanks the selection away.

    I cannot reproduce your second problem where the cursor isn't immediately visible. Regardless of how I manipulate the selection programmatically the selection point (whether multiple characters or an empty cursor) always displays for me.


    Thursday, January 9, 2014 2:04 AM
  • Thank you Rob for the quick reply.  I will look into this issue, may be my code is making RichEditBox to behave this way.

    Thursday, January 9, 2014 11:07 PM
  • Hi Rob,

    I created a custom RichEditBox by inheriting the RichEditBox for creating Dependency properties for text style to support binding.  So everytime the text selection changes, i am setting my Selection dependency property with textbox.Document.Selection.  The cursort visibility issue is solved when i set the Selection.Options with SelectionOption.Active.  With this line of code, i see the cursor visible all the time.

    Currently, the selection dependency property, i am initializing to null.  Could you please provide your suggestion if this is a good idea to initialize to null?

    Thanks for your help.

    Friday, January 10, 2014 7:34 PM
  • Initializing dependency properties to null may or may not be a good idea. It depends on the property and how it's used. I don't have enough context to know if it's appropriate for your scenario.


    Saturday, January 11, 2014 1:01 AM