0

i want to set UpdateSourceTrigger of the Binding of a PasswordBox to LostFocus or PropertyChanged dynamically.

Is there a way to bind UpdateSourceTrigger of a Binding to a DependencyProperty like this?

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

Kind Regards, Andy

Stelzy
  • 3
  • 1
  • 3
    No. A Binding is not a DependencyObject, you can't bind its properties. You may perhaps use a DataTrigger to set the Password Binding. – Clemens Jun 03 '20 at 09:42

1 Answers1

0

You can't change the UpdateSourceTrigger of an existing binding in the way you're attempting because, as Clemens points out, it is not a dependency property. Normally, you'd be able to accomplish this by using a Style with DataTriggers that replace the entire binding, but in this case you can't do that either because Password is also not a dependency property.

This later point is an intentional design choice on Microsoft's part:

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.

For more of an explanation you can take a look at this great answer from the question How to bind to a PasswordBox in MVVM.

Keith Stein
  • 6,235
  • 4
  • 17
  • 36