The implementation of validation management for a portion of a WPF LogicalTree. When FrameworkElement register themseives with the scope, it figures which field they are associated with, typically through the the property name that the element is bound to. The scope also is given a ICollection{T}. When the collection is modified, the scope makes the association between the errors and the logical field that the error should be attached to. Additionally, the scope watches for any WPF Validation errors created by any controls under the scope. If found, they are inserted into the collection. This way the ViewModel layer of an application (which supplied the collection), is now aware of these types of error.
Пример #1
0
 internal static void SetScope(DependencyObject obj, ValidationScope value)
 {
     obj.SetValue(ScopeProperty, value);
 }
Пример #2
0
        private static void OnErrorSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            var fe = obj as FrameworkElement;

            if (fe != null)
            {
                // check if there is a scope object created yet on this control.  If not create one
                // and attach it to the point in the Logical Tree that defining the scope.
                var scopeObject = GetScope(fe);

                if (scopeObject == null)
                {
                    scopeObject = new ValidationScope(fe);
                    SetScope(obj, scopeObject);
                }

                scopeObject.ErrorSource = args.NewValue as ICollection<IError>;
            }
        }