internal override void OnAttach(DependencyObject d, DependencyProperty dp) { if (IsAttached) { return; } ParentBinding.Seal(); _isAttaching = IsAttached = true; Target = d; FindSource(); // FindSource should find the source now. Otherwise, the PropertyPathNodes // shoud do the work (their properties will change when the source will // become available) _propertyPathWalker.Update(_bindingSource); //Listen to changes on the Target if the Binding is TwoWay: if (ParentBinding.Mode == BindingMode.TwoWay) { _propertyListener = INTERNAL_PropertyStore.ListenToChanged(Target, TargetProperty, UpdateSourceCallback); // If the user wants to force the Validation of the value when the element // is added to the Visual tree, we set a boolean to do it as soon as possible: if (ParentBinding.ValidatesOnExceptions && ParentBinding.ValidatesOnLoad) { INTERNAL_ForceValidateOnNextSetValue = true; } } _isAttaching = false; }
void CompleteSetValue(AsyncSetValueRequest request) { AsyncSetValueRequest pendingSetValueRequest = (AsyncSetValueRequest)GetValue(Feature.PendingSetValueRequest, null); if (pendingSetValueRequest == request) { ClearValue(Feature.PendingSetValueRequest); // if the target has gone away, ignore the request if (CheckTarget() == null) { return; } switch (request.Status) { case AsyncRequestStatus.Completed: break; case AsyncRequestStatus.Failed: object filteredException = ParentBinding.DoFilterException(ParentBindingExpression, request.Exception); Exception exception = filteredException as Exception; ValidationError validationError; if (exception != null) { if (TraceData.IsEnabled) { int k = PW.Length - 1; object value = request.Value; ReportSetValueError(k, request.TargetItem, request.Value, exception); } } else if ((validationError = filteredException as ValidationError) != null) { Validation.MarkInvalid(ParentBindingExpression, validationError); } break; } } }
//------------------------------------------------------ // // Constructors // //------------------------------------------------------ internal ClrBindingWorker(BindingExpression b, DataBindEngine engine) : base(b) { PropertyPath path = ParentBinding.Path; if (ParentBinding.XPath != null) { path = PrepareXmlBinding(path); } if (path == null) { path = new PropertyPath(String.Empty); } if (ParentBinding.Path == null) { ParentBinding.UsePath(path); } _pathWorker = new PropertyPathWorker(path, this, IsDynamic, engine); _pathWorker.SetTreeContext(ParentBindingExpression.TargetElementReference); }