是否可以将 UpdateSourceTrigger 绑定到 DependencyProperty?

Is binding of UpdateSourceTrigger to a DependencyProperty possible?

我想将 PasswordBox 绑定的 UpdateSourceTrigger 动态设置为 LostFocus 或 PropertyChanged。

有没有办法像这样将 Binding 的 UpdateSourceTrigger 绑定到 DependencyProperty?

Password="{Binding Path=PasswordProperty, Mode=TwoWay, UpdateSourceTrigger={Binding UpdateSourceTriggerProperty}"

亲切的问候, 安迪

您不能按照您尝试的方式更改现有绑定的 UpdateSourceTrigger,因为正如 Clemens 指出的那样,它不是依赖项 属性。通常,您可以通过使用 StyleDataTrigger 替换整个绑定来完成此操作,但在这种情况下您也不能这样做,因为 Password 也不是依赖项 属性.

后一点是 Microsoft 的有意设计选择:

When you get the Password property value, you expose the password as plain text in memory. To avoid this potential security risk, use the SecurePassword property to get the password as a SecureString.

如需更多解释,您可以查看此 great answer from the question How to bind to a PasswordBox in MVVM