Password box not attaching to string Password property

Dec 12, 2011 at 12:18 PM

Hello,

Im creating a login form for my wpf applicaiton... I've defined a

 

 <PasswordBox x:Name="Password" Grid.Row="2" Grid.Column="1"></PasswordBox>

but it wont' attach to the string Password defined in the viewmodel...

 

what am I missing?

Thanks

 

Coordinator
Dec 12, 2011 at 1:55 PM

It appears, that the PasswordBox in WPF is lacking the dependency property for the password value. In other words, in WPF the PasswordBox doesn't have a bindable property for the password. In Silverlight it does and the above convention binding works just fine. In WPF it looks like you have to process the PasswordChanged event.

        <PasswordBox Name="Password"   
                     cal:Message.Attach="[Event PasswordChanged] = [Action PasswordChanged($source)]"
                     Width="336"
                     Height="23"
                     Margin="47,31,0,0"
                     HorizontalAlignment="Left"
                     VerticalAlignment="Top">
        </PasswordBox>
 
    [Export]
    public class MainViewModel : Screen
    {
        private string _password;
 
        public string Password
        {
            get { return _password; }
            set
            {
                _password = value;
                NotifyOfPropertyChange(() => Password);
            }
        }
 
        public void ShowPassword()
        {
            MessageBox.Show(Password);
        }
 
        public void PasswordChanged(PasswordBox source)
        {
            Password = source.Password;
        }
    }