private static void OnElementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue == null) { BindingOperations.ClearBinding(d, DataContextProperty); BindingOperations.ClearBinding(d, HasErrorProxyProperty); BindingOperations.ClearBinding(d, ErrorsProxyProperty); BindingOperations.ClearBinding(d, NodeProxyProperty); } else { d.Bind(DataContextProperty) .OneWayTo(e.NewValue, DataContextProperty); d.Bind(HasErrorProxyProperty) .OneWayTo(e.NewValue, Scope.HasErrorProperty); d.Bind(ErrorsProxyProperty) .OneWayTo(e.NewValue, Scope.ErrorsProperty); d.Bind(NodeProxyProperty) .OneWayTo(e.NewValue, Scope.NodeProperty); } }