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 w开发者_如何学运维ay to using the add/edit usercontrols connected to a viewmodel with password?
Thank youEasy 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;
}
精彩评论