I'm building my first Xamarin MvvmCross application at the moment and I'm currently looking at validating user input to the view models.
Doing a lot of searching around everything (including the MvvmCross team) link to this plugin:
This plugin makes use of a very old version of MvvmCross v3. I have tried taking the code from this plugin and building it directly into my application Core project until I came across the Bindings breaking change. I then came to the conclusion that this plugin would actually require a complete re-write due to this in order to use the latest version of MvvmCross.
So I'm now a little stuck.
What is the currently recommended best approach for performing input validation in a view model?
Best How To :
I use MVVM Validation Helpers http://www.nuget.org/packages/MvvmValidation/
It's a simple validation library that's easy to use. It's not tied to MvvmCross.
Here's how I use it, for example, in my SigninViewModel:
private async void DoSignin()
IsBusy = true;
Result = "";
var success = await SigninService.SigninAsync(Email, Password);
Result = "";
Result = "Invalid email/password. Please try again.";
catch (Exception ex)
Result = "Error occured during sign in.";
IsBusy = false;
private bool Validate()
var validator = new ValidationHelper();
validator.AddRequiredRule(() => Email, "Email is required.");
validator.AddRequiredRule(() => Password, "Password is required.");
var result = validator.ValidateAll();
Errors = result.AsObservableDictionary();
The nice part of it is that you can get Errors as a collection and bind them in your view. For Android, I set the Error property to the keyed Error message.
local:MvxBind="Text Email; Error Errors['Email']"
local:MvxBind="Text Password; Error Errors['Password']"
And here's what the validation looks like: