清除后不返回 PasswordBox 占位符文本

PasswordBox placeholder text isn't returning when cleared

所以我有一个 PasswordBox:

<PasswordBox x:Name="pwbPassword" PlaceholderText="Password" 
             Password="{x:Bind Path=local:Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

但是我也有一个明确的功能,其中包含:

Password = null

我遇到的问题是 PlaceholderText 没有恢复,而是该框留空。

这是一个错误还是我遗漏了什么?

PasswordBox placeholder text isn't returning when cleared

我检查了你的代码,Password是字符串属性,请绑定字符串字段。

<PasswordBox

    Name="MyPassswordBox"
    Height="44"
    MaxLength="20"
    Password="{x:Bind PassWord, Mode=TwoWay}"
    PlaceholderText="Input your Password"
    />

代码隐藏

private string _passWord;

 public event PropertyChangedEventHandler PropertyChanged;
 private void OnPropertyChanged([CallerMemberName] string propertyName = null)
 {
     if (PropertyChanged != null)
     {
         this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
     }
 }
 public string PassWord
 {

     get { return _passWord; }
     set
     {
         _passWord = value;
         OnPropertyChanged();

     }
 }

如果要清除密码,请将PassWord设置为null。

private void Button_Click(object sender, RoutedEventArgs e)
{
    PassWord = null;
}

我测试过,PlaceholderText会恢复