Exemplo n.º 1
0
 private void SetSourceFromProperty()
 {
     if (FrameworkElementService.GetIsFirstVisit(this))
     {
         var expression = this.GetBindingExpression(PropertyProperty);
         if (expression != null && this.Source == null)
         {
             this.SetValue(Validator.SourceProperty, expression.DataItem as FrameworkElement);
         }
     }
 }
Exemplo n.º 2
0
        private static void TriggerElementPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Validator validator = d as Validator;

            if (FrameworkElementService.GetIsFirstVisit(validator.TriggerElement))
            {
                validator.RegisterTriggerValidationEvent();
                FrameworkElementService.SetIsFirstVisit(validator.TriggerElement, false);
            }

            ValidationService.GetValidators(validator.TriggerElement).Add(validator);
        }
Exemplo n.º 3
0
        private static void OnceLoaded(object sender, RoutedEventArgs e)
        {
            var element   = sender as FrameworkElement;
            var condition = FrameworkElementService.GetUnLoadedCondition(element);

            if (condition.Condition())
            {
                condition.Action();
                element.Loaded -= OnceLoaded;
                element.ClearValue(FrameworkElementService.UnLoadedConditionProperty);
            }
        }
Exemplo n.º 4
0
        protected static void ValidPropertyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Validator validator = d as Validator;

            validator.SetSourceFromProperty();

            if (validator.HasSourceContext)
            {
                UIThread.BeginInvoke(() =>
                {
                    var isValid       = validator.IsValid;
                    validator.IsValid = validator.InnerValidateWithError();
                    if (!isValid && !validator.IsValid && !FrameworkElementService.GetIsFirstVisit(validator))
                    {
                        validator.GapValidate();
                    }
                }, DispatcherPriority.Normal);
            }
            else
            {
                validator.IsValid = true;
            }
            FrameworkElementService.SetIsFirstVisit(validator, false);
        }