title: WPF Custom Validation MVVM
body: <p>I'm having problems coming up with a good way to validate user input. I'm aware that I can implement <code>IDataErrorInfo</code> to do simple validation on user input, and I have read several articles on the subject (such as <a href="https://stackoverflow.com/questions/63646/wpf-data-binding-and-validation-rules-best-practices">this</a> and <a href="http://karlshifflett.wordpress.com/mvvm/input-validation-ui-exceptions-model-validation-errors/" rel="nofollow noreferrer">this</a>) without seeing the light. Let me explain the two problems I have:</p>
  
  <p>Basically I'm implementing an application that allows the user to create users in a system. My viewmodel uses a set of WCF services to save its work. When someone wants to create a new user I can easily see how I can use IDataErrorInfo to disallow empty usernames being entered. But if the username is not empty and a call to the <code>CreateUser</code> service fails because the username already exists, then how do I hightlight the user name textbox? My second problem is with two <code>PasswordBox</code>'es that I have, Password and RepeatPassword. Since I cannot databind to the <code>Password</code> property I don't see how I can use the <code>IDataErrorInfo</code> approach to validate that the password is not empty. Furthermore I need to make sure that the two passwords are identical, so again this calls for some custom mechanism. </p>
  
  <p>I'm by no means an expert on WPF and maybe I'm missing some obvious solution, so please, if you can, shed some light on how I can solve this.</p>
  
  <p>Thanks in advance,</p>
  
  <p>Klaus</p>