【问题标题】:PasswordBox placeholder text isn't returning when clearedPasswordBox 占位符文本在清除时不返回
【发布时间】:2020-01-05 01:05:02
【问题描述】:

所以我有一个PasswordBox

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

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

Password = null

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

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

【问题讨论】:

    标签: c# uwp placeholder passwordbox


    【解决方案1】:

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

    我检查了你的代码,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会恢复的。

    【讨论】:

      猜你喜欢
      • 2012-01-21
      • 1970-01-01
      • 2020-07-08
      • 2014-01-26
      • 2019-12-19
      • 2018-01-29
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多