0

I'm using MVVM and the model has password field. From what I've found on web, when handling this password you must implement custom class for binding and use PasswordBox. I think this is overhead. Could you point me to a better way to using the add/edit usercontrols connected to a viewmodel with password?
Thank you

gapo
  • 505
  • 1
  • 7
  • 19
  • Everything is binding in MVVM. – Jeaf Gilbert Aug 03 '10 at 15:13
  • 2
    Here's another SO question that deals with this: http://stackoverflow.com/questions/1483892/wpf-binding-to-the-passwordbox-in-mvvm-working-solution – Eric Olsson Aug 03 '10 at 15:15
  • 1
    I'd highly recommend reading through the top answer in Eric's link, and paying attention to the bit about not storing passwords as part of your Model anywhere for security reasons. – Rachel Nov 07 '12 at 20:07

1 Answers1

0

Easy way but not MVVM:

Xaml

<PasswordBox PasswordChanged="PasswordBox_PasswordChanged"

Xaml.cs

private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
    if (viewModel != null && sender is PasswordBox)
        viewModel.DatabasePassword = ((PasswordBox) sender).Password;
}

private void Load()
{
    //Fills viewModel.DatabasePassword
    viewModel.ReadData();

    PasswordBox.Password = viewModel.DatabasePassword;
}
remarkies
  • 113
  • 10