在WPF中validationPasswordBox

有没有办法在validationPasswordBox时在AdornedElementPlaceholder中显示错误消息。

我有这样的事情:

        

和我的BaseControlStyle我使用该validation

   

它的工作就像一个几乎所有控件(Combobox,DateTimePicker,TextBox)的魅力,但是当我想为passwordBox使用相同的样式时,它不起作用。

在此处输入图像描述 在图片中,您可以看到它与simpe TextBox一起使用但不与PasswordBox一起使用。 我不知道如何提取错误消息以在工具提示中显示它AdornedElementPlaceholder

它显示Username属性的错误消息

 [Required(ErrorMessage = "Please enter username.")] 

我不想用passwordBox实现同样的function,以便在输入密码时向用户提供有关错误(约束)的反馈

任何帮助都非常感谢。

提前致谢 :)

编辑:

我用它来做密码属性

 [Required(ErrorMessage = "Please enter password.")] [RegularExpression(@"^.*(?=.{8,})(?=.*\d)(?=.*[az])(?=.*[AZ])(?=.*[^a-zA-Z0-9]).*$")] [StringLength(maximumLength: 15, ErrorMessage = "Minimum 8 and maximum 15 characters.", MinimumLength = 8)] public string Password { get { return GetValue(); } set { SetValue(value); } } 

并使用PasswordBoxAssistant绑定到该属性

  

并使自定义PasswordBoxStyle为BasedOn ControlBaseStyle

  

我用TextBox做了同样的事情,但它不能用于PasswordBox

信息:我想知道为什么你投票结束这个问题? 如果对此甚至是指南有答案,我很乐意自己关闭,如果没有,请在投票结束前给我答复。 谢谢。

我找到了答案。 不得不改变

  

把它放进去

   

显然它只在Trigger内部工作时,TextBox可以像默认和Trigger一样工作。