“WPF. I love you. Really ! But sometimes… i hate you !”
So, we all know that the WPF has it´s “own reality”. Sometimes genius, sometimes strange, and sometimes… weird ! In this case, it isn´t something like a strange deep technical behaviour. Instead i would call it a “design thing”.
Let me show what i mean, with the help of a little real time story, happened to me today:
It´s midnight and i code a simple test tool, direct from mind to keyboard. The tool needs to login somewhere, so i have to enter a password. I WPF´ed a lot in the past, but for inexplicable reasons i never had to use a password input field. Hmm, seems like i have to use a TextBox and set some property to “password char” or something else. Thought it works like in Windows.Forms, maybe. Ok, no password char or anything else. Google. Ok, TextBox do not have any password-related stuff cause of security reasons. Uuum what ? Security reasons ? Google: “You have to use PasswordBox now”. Ok, no problem. Thought: “Nice, they make it an own control”. Use PasswordBox. Cause we live in the “new world”, thanks to WPF and MVVM, we use ViewModels, sync Control-State via DataBinding with the ViewModel and have better testability and decoupling. Makes us happy. So, i wanna bind my “password value” from the PasswordBox to my ViewModel. And it hits me like a truck: “Binding can only used with DependencyProperties”. WTF ? The Password-Property is NOT a DependencyProperty ? Why not ??? I figured out they have a “PasswordChanged”-Event and the Non-DependencyProperty “Password”, and you can get your password in cleartext (!) from there, in the event in your code-behind file. And then i thought again: “Security reasons… ?”. So i had to read about it. And it´s weird.
Read that: http://blog.functionalfun.net/2008/06/wpf-passwordbox-and-data-binding.html
If you don´t have a SecureString or any other encrypted password data, then at some point, it will pass the ram. I really don´t know where´s the logic here. Finally i think, also at Microsoft, sometimes some things gonna weird :)