Because security matters, you will need at one point to use a PasswordBox in your WPF application (you know, the textBox hiding the password with stars).

But Microsoft didn’t make this control bindable for security reasons (in memory access).

So if you’re using MVVM, it will be a bit tricky. Different solutions exist, but really not convenient or will not respect the MVVM principles.

Samuel Jack posted on his blog a simple solution to make it bindable.

Here is a simple example to create a PasswordBoxHelper class:

Then reference it in your View:

And then use it in your control:

As simple as that… But to go deeper, you could read this article talking about the TextBox validation with IDataErrorInfo.

Happy coding! 🙂