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

626 Views Asked by At

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

2

There are 2 best solutions below

0
t4nhpt On BEST ANSWER

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 = "";
    }
}
0
CAMOBAP On

In my case Page.UpdateLayout() solved this issue