Home > DeveloperSection > Forums > Input Validation and UI Exceptions with MVVM Light
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    July-19-2013 3:06 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 3317  View(s)
Rate this:

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

Total Post:100

Points:700
Posted on    July-19-2013 6:20 AM

You 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...

}


Don't want to miss updates? Please click the below button!

Follow MindStick