INPUT VALIDATION AND UI EXCEPTIONS WITH MVVM LIGHT

Jeet Verma

Total Post:110

Points:776
Posted by  Jeet Verma
WPF 
WPF
 4003  View(s)
Ratings:
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.)

  1. Vijay Shukla

    Post:100

    Points:700
    Re: Input Validation and UI Exceptions with MVVM Light

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

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!