-
Notifications
You must be signed in to change notification settings - Fork 1.4k
TextBoxMask cursor at beginning if empty #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextBoxMask cursor at beginning if empty #757
Conversation
| displayText = displayText.Replace(key, placeHolder); | ||
| } | ||
|
|
||
| // if the textbox got focus and the textbox is emply (contains only mask) set the textbox cursor at the beginning to simulate normal TextBox behavior if it is empty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "emply" instead of "empty"
…TextboxCursorBeginnging
|
|
||
| private static void Textbox_GotFocus(object sender, RoutedEventArgs e) | ||
| { | ||
| var textbox = sender as TextBox; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest doing a single if (textbox == null) return; after this instead of all these null checks on every reference to textbox.
Having said that, this is a private method only used with the TextBox.GotFocus event, so the sender should always be set with the current instance of the TextBox control!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Do explicit cast and remove ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I need to ask @deltakosh is there is any chance I can get a null here from the framework ?
|
|
||
| private static void Textbox_GotFocus(object sender, RoutedEventArgs e) | ||
| { | ||
| var textbox = sender as TextBox; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Do explicit cast and remove ?
| } | ||
|
|
||
| // if the textbox got focus and the textbox is empty (contains only mask) set the textbox cursor at the beginning to simulate normal TextBox behavior if it is empty. | ||
| if (string.Equals(textbox.Text, displayText)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably just always put the cursor to the end of where the user has entered text. If they have entered no text, it's at 0. If they have entered 3 of 10 characters (eg: phone number) then it's at 3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, for the phone number example it would be at 4 to bypass the first dash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IbraheemOsama any thoughts on this ?
referencing issue #756