I am using MVVM using GalaSoft light Framework(mvvmlight(wpf4)). I have problems Validating Data input from the user and Displaying MessageBox indicating empty/incorrect input from the user,I wanted to use INotifyDataErrorInfo and this article , but don't support in wpf4.
private string _password;
private string _userName;
[Required(AllowEmptyStrings = false, ErrorMessage = "Username is required")]
public string UserName
{
get { return _userName; }
set
{
if (_userName != value)
{
// ValidateProperty("UserName", value);
_userName = value;
base.RaisePropertyChanged("UserName");
}
}
}
[Required(AllowEmptyStrings = false, ErrorMessage = "Password is required")]
public string Password
{
get { return _password; }
set
{
if (_password != value)
{
// ValidateProperty("Password", value);
_password = value;
base.RaisePropertyChanged("Password");
}
}
}
How to use Messanger for input validation in mvvm light ?(send a message from save button to the ViewModel to check the input values.)
Vijay Shukla
19-Jul-2013You can send message on button.click event like this..
Messenger.Default.Send<string>("showattraction", "attraction");
first string is message and other is token for varifying it..
and where you recive this message do this..in constructor..
essenger.Default.Register<string[]>(this, "attraction", GetLineDetails);
do your work in GetLineDetails method..
public void GetLineDetails(string[] Message)
{
// work here...
}