0

How to set TextBox cursor on the right corner of the TextBox.

Like this:

While there's a Text inside the TextBox

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109

2 Answers2

1

You can use HorizontalContentAlignment property:

<TextBox HorizontalContentAlignment="Right" VerticalAlignment="Top"/>

The result:

enter image description here

Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
  • This does not seem related to the question being asked. `HorizontalContentAlignment` has nothing to do with the cursor position. – Brandon Kramer Mar 07 '17 at 14:15
  • @BrandonKramer Test it and you can see after setting `HorizontalContentAlignment` to right you see the cursor position in right. See the image in my updated answer. I got this result from the above code. – Salah Akbari Mar 07 '17 at 14:38
  • 1
    But that will also set the Content to the right side, which is not what he asked for. As far as I can see, he only wants the cursor on the right. – Brandon Kramer Mar 07 '17 at 14:39
  • @BrandonKramer And can you say what's the point of cursor in right side and content in left side? I think it will be meaningless. – Salah Akbari Mar 07 '17 at 14:43
  • The downvote was because I didn't realize it moved the cursor, so I thought it was not related to the question. I removed it. As for the point of this, I have no idea. – Brandon Kramer Mar 07 '17 at 14:45
  • Though, based on his image I agree with NicoRiff, that he seems to be needing a PlaceHolder. – Brandon Kramer Mar 07 '17 at 14:47
  • @S.Akbari just look at the OP pic. What I think he really wants is a PlaceHolder, he just typed right when he wanted to say left :) – Pikoh Mar 07 '17 at 14:47
  • @BrandonKramer The title and the image are saying two different things completely and unfortunately the user is too new to SO to clarify the question, The title says *How to set TextBox cursor on the rigth corner of the TextBox* and the image is about `PlaceHolder`. – Salah Akbari Mar 07 '17 at 14:50
  • No, I agree with you that it is unclear. I was just speculating that based on his image he probably is looking for `PlaceHolder` text for an empty text box, rather then trying to move the cursor to the right as the title says. – Brandon Kramer Mar 07 '17 at 14:52
  • @BrandonKramer I even guess that he probably posted a different image from his PC accidentally. Or as Pikoh said *he just typed right when he wanted to say left* or anything else. :-) – Salah Akbari Mar 07 '17 at 14:57
  • Yeah, the only way we will know is if he edits his question to make it more clear. – Brandon Kramer Mar 07 '17 at 14:58
  • @BrandonKramer yep! im looking for a placeholder. but im doing my own version. because when im searching for a placeholder sample, the codes are too complicated. – David Peralta Mar 18 '17 at 13:12
0

If you want to set the Caret position, you have to play with CaretIndex property,for example:

<TextBox Text="Username" CaretIndex="0"/>;

But as @NicoRiff says in a comment, what you probably want is a PlaceHolder. If that's the case, see this question

Community
  • 1
  • 1
Pikoh
  • 7,582
  • 28
  • 53