Validate Ria Service's Data Model in MVVM

Aug 21, 2010 at 8:54 PM

I'm getting close to finishing up my first CM app, but am unsure how to do validation.  I'm trying to use the validation built into RIA services.

My ViewModel is -

    public class DriverEditViewModel : PropertyChangedBase, IViewAware, IDeactivate
    {
        public DriverEditViewModel()
        {
            cnd_Drivers = new cnd_Drivers {driver_Name = ""};
            DialogResult = CommandResult.NoCommand;
        }

        public DriverEditViewModel(cnd_Drivers source)
        {
            _cnd_Drivers = new cnd_Drivers();
            _cnd_Drivers = source;
            DialogResult = CommandResult.NoCommand;
        }

        #region Declarations

        private cnd_Drivers _cnd_Drivers;
        private DriverEditView _localView;
        private CoreRiaContext _dataContext;

        #endregion

        #region Properties

        public CommandResult DialogResult { get; set; }

        public cnd_Drivers cnd_Drivers
        {
            get { return _cnd_Drivers; }
            set
            {
                _cnd_Drivers = value;
                driver_Name = value.driver_Name;
            }
        }

        public Boolean driver_Active
        {
            get { return _cnd_Drivers.driver_Active; }
            set
            {
                _cnd_Drivers.driver_Active = value;
                NotifyOfPropertyChange(() => driver_Active);
            }
        }

        public Int32 driver_ID
        {
            get { return _cnd_Drivers.driver_ID; }
            set { _cnd_Drivers.driver_ID = value; }
        }

        public String driver_Name
        {
            get { return _cnd_Drivers.driver_Name; }
            set
            {
                _cnd_Drivers.driver_Name = value.Trim();
                NotifyOfPropertyChange(() => driver_Name);
                NotifyOfPropertyChange(() => CanSaveBtn);
            }
        }

        #endregion

XMAL code that CM binds to is

           <TextBox  Name="driver_Name" Grid.Column="1"
             HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.ColumnSpan="2"  />
            <CheckBox Grid.Column="1" Grid.Row="1" Name="driver_Active" Grid.ColumnSpan="2"  IsThreeState="False" />
My question is how to use the builtin validation that is in CM's ViewModelBinder?