I have come across a problem with binding to a PasswordBox
. It seems it\'s a security risk but I am using the MVVM pattern so I wish to bypass this. I found som
Here's my take on it:
Using an attached property to bind the password defeats the purpose of securing the password. The Password property of a password box is not bindable for a reason.
Passing the password box as command parameter will make the ViewModel aware of the control. This will not work if you plan to make your ViewModel reusable cross platform. Don't make your VM aware of your View or any other controls.
I don't think introducing a new property, an interface, subscribing to password changed events or any other complicated things is necessary for a simple task of providing the password.
XAML
Code behind - using code behind does not necessarily violate MVVM. As long as you don't put any business logic in it.
btnLogin.CommandParameter = new Func(()=>pbPassword.Password);
ViewModel
LoginCommand = new RelayCommand>(getpwd=> { service.Login(username, getpwd()); });