Unable to data-bind to a PasswordBox

When I attempt to bind to the Password property of the PasswordBox (binded to a property on an object that returns a string), I get the following error:

Object of type 'System.Windows.Data.Binding' cannot be converted to type 'System.String'.

Is string the wrong type....I tried char[] with the same result.


Answer this question

Unable to data-bind to a PasswordBox

  • sandyk

    PasswordBox.Password doesn't have a corresponding DependencyProperty, so you can't data-bind to it.

    Exposing a DependencyProperty would require us to store the PasswordBox content plain text in memory in the property system -- which is a security concern.  The PasswordBox encrypts its content and only generates plain text on demand when a caller references the Password CLR property.


  • dpechter

    I would like to bind to the Password box for the reason why you would want to data-bind anything...that is to enable the UI (XAML) to be less coupled to the application logic.  Without binding, I would have to know the name associated with the password box and then from code get a reference to the password box and directly access its Password property.  With binding, I simply know that there some data object bound to the page (or window, dialog, etc) and then get the password value from that object.
  • Georges Vidal

    You can't bind the property beause it is not a DependencyProperty. It is probably not a DP because Microsoft doesn't see any point in it being one and I'm inclined to share that perspective. In what scenario would you ever want to databind to a password box

    HTH,
    Drew

  • Annie C D B

    Hi,

    I want to use the Password of a PasswordBox as CommandParameter of a Button.

    Since the Password can't be dinding, how to do so



  • Unable to data-bind to a PasswordBox