0
Reply

How to apply a validation rule for control in WPF-MVVM

jeevan mummadi

jeevan mummadi

Mar 23 2013 1:18 PM
1.6k
Hi All,

Currently I am working on WPF with MVVM patern. I created one sample apps like this

View
------

<TextBox Grid.Row="0" Grid.Column="1" Width="100" HorizontalAlignment="Center" Text="{Binding Student.Name, Mode=TwoWay}"/>

ViewModel
--------------

public Student Student
        {
            get 
            {
                return _student;
            }
            set 
            {
                _student = value;
                NotifyPropertyChanged("Student");
            }
        }


Model
--------
public class Student
    {
        public string Name { get; set; }
        
    }

Can you please any one explain about how to validate a property for example "Name" 
We have to apply validation rule in ViewModel or Model level.