Beispiel #1
0
        private static void OnTargetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Label label = d as Label;

            if (label != null)
            {
                label.LoadMetadata(false);
                label._errors.Clear();
                FrameworkElement oldElement = e.OldValue as FrameworkElement;
                FrameworkElement newElement = e.NewValue as FrameworkElement;
                EventHandler <ValidationErrorEventArgs> bindingHandler = new EventHandler <ValidationErrorEventArgs>(label.Target_BindingValidationError);
                if (oldElement != null)
                {
                    oldElement.BindingValidationError -= bindingHandler;
                }
                if (newElement != null)
                {
                    newElement.BindingValidationError += bindingHandler;
                    ReadOnlyObservableCollection <ValidationError> newErrors = Validation.GetErrors(newElement);
                    if (newErrors.Count > 0)
                    {
                        // Only the first error is used by binding
                        label._errors.Add(newErrors[0]);
                    }
                }

                label.ParseTargetValidState();
            }
        }
Beispiel #2
0
        private static void OnPropertyPathPropertyChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)
        {
            Label label = depObj as Label;

            if (label != null && label.Initialized)
            {
                label.LoadMetadata(false);
                // Changing the PropertyPath sometimes requires an update for the validation state, since it might be stale.
                label.ParseTargetValidState();
            }
        }