tags:

views:

606

answers:

2

Hi everyone. I'm having problems coming up with a good way to validate user input. I'm aware that I can implement IDataErrorInfo to do simple validation on user input, and I have read several articles on the subject (such as this and this) without seeing the light. Let me explain the two problems I have:

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 CreateUser service fails because the username already exists, then how do I hightlight the user name textbox? My second problem is with two PasswordBox'es that I have, Password and RepeatPassword. Since I cannot databind to the Password property I don't see how I can use the IDataErrorInfo 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.

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.

Thanks in advance,

Klaus

+1  A: 

For performing custom validation I would recommend you the FluentValidation.NET library.

Darin Dimitrov
+1 thank you for pointing me to that. It looks useful.
klausbyskov
+1  A: 

We implement custom validation and give every field an IsDirty, IsValid and ErrorMessage property. then we style the controls, textboxes, combo's etc. and use data triggers to display the objects state, if it's invalid we might place a small check on the control and when the user hovers over have a tooltip with the error message.

here is a workaround to the password box, there are security issues here, but it all depends how secure you need to be doesn't it?

Aran Mulholland
+1 Thanks, I can live with the security issue. It's not worse than the TextBox+masking in winforms anyway.
klausbyskov