TextBoxMask cursor at beginning if empty #757

Merged
merged 6 commits into from Jan 14, 2017

Projects

None yet

7 participants

@IbraheemOsama
Collaborator

referencing issue #756

+ 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.
@ScottIsAFool
ScottIsAFool Jan 5, 2017 Collaborator

Typo: "emply" instead of "empty"

textbox.SetValue(OldTextProperty, textbox.Text);
textbox.SelectionStart = 0;
}
+ private static void Textbox_GotFocus(object sender, RoutedEventArgs e)
+ {
+ var textbox = sender as TextBox;
@PedroLamas
PedroLamas Jan 9, 2017 Collaborator

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!

@skendrot
skendrot Jan 9, 2017 Collaborator

Agreed. Do explicit cast and remove ?

@IbraheemOsama
IbraheemOsama Jan 14, 2017 Collaborator

actually I need to ask @deltakosh is there is any chance I can get a null here from the framework ?

textbox.SetValue(OldTextProperty, textbox.Text);
textbox.SelectionStart = 0;
}
+ private static void Textbox_GotFocus(object sender, RoutedEventArgs e)
+ {
+ var textbox = sender as TextBox;
@skendrot
skendrot Jan 9, 2017 Collaborator

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))
@skendrot
skendrot Jan 9, 2017 Collaborator

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.

@skendrot
skendrot Jan 9, 2017 edited Collaborator

Actually, for the phone number example it would be at 4 to bypass the first dash

@hermitdave
hermitdave Jan 10, 2017 Collaborator

@IbraheemOsama any thoughts on this ?

@IbraheemOsama IbraheemOsama merged commit f81f144 into Microsoft:dev Jan 14, 2017

1 check passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@IbraheemOsama IbraheemOsama deleted the IbraheemOsama:MaskedTextboxCursorBeginnging branch Jan 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment