How to binding data to PasswordBox (2 way)?


  • Hi guys,

    I am trying to use a PasswordBox in a basic login window with Avalon. 
    The user information is stored in an MSSQL database. 
    Basically I want to Binding data from Password column in MSSQL to PasswordBox in XAML. However, I get an error when I perform binding data like this:

    "Object of type 'System.Window.DataBinding' cannot be converted to type 'System.String' "

    Please help me...


    Monday, June 26, 2006 1:44 AM


All replies

  • Could you paste in the code. Looks like the object obtained cannot be converted to a string. Maybe a type cast could help.
    Monday, June 26, 2006 3:44 AM
  • Hi guys,

    Example, I got a table with AdminPassword column in MSSQL. Column type is varchar(20).

    I bind this column to elelment using XAML like this:

    <PasswordBox Name="textBoxPassword" Password ="{Binding Path=AdminPassword}"  ></PasswordBox >

    However, when I run my application, system show error like message that I sent before.

    Please help me show out this problem. Thanks


    Tuesday, June 27, 2006 1:23 AM
  • you can't.  see this thread for the reason why.

    Friday, June 30, 2006 8:32 PM
  • Instead of bind a password property to the UI PasswordBox control I bind UI to the PasswordBoxProperty of the session controller. How it could affect the security?

    [c# code]

    public class SessionControl : ContentElement

        public static readonly DependencyProperty PasswordBoxProperty
          = DependencyProperty.Register("PasswordBox", typeof(PasswordBox), typeof(SessionControl));


        public SessionControl()
             SetValue(PasswordBoxProperty, new PasswordBox());

        public bool IsLoginCorrect
           return ValidatePassword(((PasswordBox)((SessionControl)ds.Session).GetValue(SessionControl.PasswordBoxProperty)).Password);



    [xaml code]
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Label Content="PIN:"/>
              Margin="5,0,0,0" Width="150"
              Content="{Binding Session.PasswordBox}"/>

    Monday, March 24, 2008 8:42 AM