By accepting the help at the URL provided by Terence, I have prepared the solution for you below. This can be used to ensure that all properties are set before calling the service.
public class PersonViewModel : EntityBase { private readonly RelayCommand saveCommand; public PersonViewModel(IServiceAgent serviceAgent) { saveCommand = new RelayCommand(Save) { IsEnabled = true }; } public RelayCommand SaveCommand // Binded with SaveButton { get { return saveCommand; } } public String Name // Binded with NameTextBox { get { return name; } set { name = value; PropertyChangedHandler("Name"); ValidateName("Name", value); } } public Int32 Age // Binded with AgeTextBox { get { return age; } set { age = value; PropertyChangedHandler("Age"); ValidateAge("Age", value); } } private void ValidateName(string propertyName, String value) { ClearErrorFromProperty(propertyName); if (/*SOME CONDITION*/) AddErrorForProperty(propertyName, "/*NAME ERROR MESSAGE*/"); } private void ValidateAge(string propertyName, Int32 value) { ClearErrorFromProperty(propertyName); if (/*SOME CONDITION*/) AddErrorForProperty(propertyName, "/*AGE ERROR MESSAGE*/"); } public void Save() { ValidateName("Name", name); ValidateAge("Age", age); if (!HasErrors) { //SAVE CALL TO SERVICE } } }
source share