Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Move list from the view model to the validation rules class

$
0
0

HI ,

Im using the following example and it the list which should need to do the validation to is currently 

inside the validation rules class but now I need to get it from outside and the list can be changed during RT,

how can I send the list from the view model to the validation rules class

    public class Propeation : ValidationRule
    {
        private readonly List<String>  validValues = new List<String> { "aa", "bb", "cc", "dd" };
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if(value == null)
                return new ValidationResult(false, "The Field are not match");

            string val = value.ToString().Trim();
            bool isValid = !string.IsNullOrEmpty(val) && validValues.Contains(val);
            ValidationResult result = null;
            result = isValid
                         ? new ValidationResult(true, null)
                         : new ValidationResult(false, "The Field are not match");

            return result;
        }
    }

<TextBox><TextBox.Text><Binding Path="NameOfViewModelPropery" UpdateSourceTrigger="PropertyChanged"><Binding.ValidationRules><local:PropertiesMapValidation ValidatesOnTargetUpdated="True"/></Binding.ValidationRules></Binding></TextBox.Text></TextBox>




Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>