Skip to content

Conversation

@IbraheemOsama
Copy link
Member

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.
Copy link
Contributor

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"


private static void Textbox_GotFocus(object sender, RoutedEventArgs e)
{
var textbox = sender as TextBox;
Copy link
Member

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!

Copy link
Contributor

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 ?

Copy link
Member Author

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;
Copy link
Contributor

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))
Copy link
Contributor

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.

Copy link
Contributor

@skendrot skendrot Jan 9, 2017

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

Copy link
Contributor

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 ?

@IbraheemOsama IbraheemOsama merged commit f81f144 into CommunityToolkit:dev Jan 14, 2017
@IbraheemOsama IbraheemOsama deleted the MaskedTextboxCursorBeginnging branch January 16, 2017 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants