コード例 #1
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            try
            {
                if (value == null)
                {
                    return(new ValidationResult(false, "You must enter a non-empty value"));
                }


                if (value is BindingGroup) //Since our XAML has ValidationStep="UpdatedValue" />, then our value is now of type BindingExpression, not the normal string that we expected.
                {
                    BindingGroup bg = value as BindingGroup;
                    //CiresonTimerActivity ta = bg.Owner.
                    StackPanel sp = bg.Owner as StackPanel;
                    CiresonTimerActivityViewModel taViewModel = sp.DataContext as CiresonTimerActivityViewModel;
                    string strError = null;
                    if (taViewModel.HasValidDateInfoEntered(out strError))
                    {
                        return(ValidationResult.ValidResult);
                    }
                    else
                    {
                        return(new ValidationResult(false, strError));
                    }
                }


                return(new ValidationResult(false, "Was not expecting this obejct here..."));
            }
            catch
            {
                return(new ValidationResult(false, "You must make a selection and enter a value"));
            }
        }