"Hint text" 将文本设置为 PhoneTextBox 时不隐藏(工具包,WP8.1)

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

我使用 PhoneTextBox (Microsoft.Phone.Controls.Toolkit) 来接收用户的输入。如果用户之前将文本设置为文本框,我想为用户保留此文本。

但是当我导航到该视图时,文本框同时显示“用户文本”和“提示文本”。

如何防止 PhoneTextBox 在设置文本时显示提示文本?

见下图。用户之前在字段 First Name 中输入的文本已被“提示文本”

覆盖

在这种情况下,我找到了一个临时解决方案。 我自定义了PhoneTextBoxclass。在 TextChanged 事件中,我检查文本框的内容,然后将 Hint Text 更改为有效值。在 xaml 中使用 SbPhoneTextBox 而不是 PhoneTextBox。问题已解决: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 = "";
    }
}

在我的案例中 Page.UpdateLayout() 解决了这个问题