windows-phone-8.1silverlight-toolkithint

"Hint text" not hide when set text to PhoneTextBox (toolkit, WP8.1)


I use PhoneTextBox (Microsoft.Phone.Controls.Toolkit) to receive input from user. If user has set text to textbox before, I want to keep this text for user.

But when I navigate to this view, the textbox show both "user text" and "hint text".

How I can prevent PhoneTextBox display hint text when I set text to it?

See the picture below. The text user enter before in field First Name has been covered by the "hint text"

enter image description here


Solution

  • I found a temporary solution in this case. I customize the PhoneTextBox class. On TextChanged event, I check the content of text box, then change the Hint Text to valid value. Use the SbPhoneTextBox instead PhoneTextBox in xaml. Problem solved :D

    public class SbPhoneTextBox : PhoneTextBox
    {
        public SbPhoneTextBox()
        {
            this.TextChanged += SbPhoneTextBox_TextChanged;
        }
    
        void SbPhoneTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (this.Text == string.Empty)
                this.Hint = this.Tag.ToString();
            else
                this.Hint = "";
        }
    }