private static void OnIsValidationScopeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var fe = d as FrameworkElement; if (fe == null) { return; } if (Equals(e.NewValue, true)) { var proxy = fe.GetValue(ValidationProxyProperty); if (proxy == null) { proxy = new ValidationProxy(fe); fe.SetValue(ValidationProxyProperty, proxy); } var proxyCollection = new ErrorProxyCollection(); d.SetErrorProxies(proxyCollection); AddErrorHandler(fe, OnError); } else { var proxy = (ValidationProxy)fe.GetValue(ValidationProxyProperty); if (proxy != null) { proxy.Dispose(); } var collection = d.GetErrorProxies(); if (collection != null) { collection.Dispose(); } d.SetErrorProxies(null); RemoveErrorHandler(fe, OnError); } }
public static void SetErrorProxies(this DependencyObject element, ErrorProxyCollection value) { element.SetValue(ErrorProxiesPropertyKey, value); }