// Token: 0x0600760B RID: 30219 RVA: 0x0021AADE File Offset: 0x00218CDE internal override object GetObject(DependencyObject d, ObjectRefArgs args) { if (this._element == null) { return(this._object); } return(this._element.Target); }
// Token: 0x06007601 RID: 30209 RVA: 0x0021A6FC File Offset: 0x002188FC internal override object GetDataObject(DependencyObject d, ObjectRefArgs args) { object obj = this.GetDataObjectImpl(d, args); DependencyObject dependencyObject = obj as DependencyObject; if (dependencyObject != null && this.ReturnsDataContext) { obj = dependencyObject.GetValue(ItemContainerGenerator.ItemForItemContainerProperty); if (obj == null) { obj = dependencyObject.GetValue(FrameworkElement.DataContextProperty); } } return(obj); }
/// <summary> Returns the data object associated with the referenced object. /// Often this is the same as the referenced object. /// </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> /// <exception cref="ArgumentNullException"> d is a null reference </exception> internal override object GetDataObject(DependencyObject d, ObjectRefArgs args) { object o = GetDataObjectImpl(d, args); DependencyObject el = o as DependencyObject; if (el != null && ReturnsDataContext) { // for generated wrappers, use the ItemForContainer property instead // of DataContext, since it's always set by the generator o = el.GetValue(ItemContainerGenerator.ItemForItemContainerProperty); if (o == null) { o = el.GetValue(FrameworkElement.DataContextProperty); } } return(o); }
private object GetDataObjectImpl(DependencyObject d, ObjectRefArgs args) { if (d == null) { return(null); } switch (_relativeSource.Mode) { case RelativeSourceMode.Self: break; // nothing to do case RelativeSourceMode.TemplatedParent: d = Helper.GetTemplatedParent(d); break; case RelativeSourceMode.PreviousData: return(GetPreviousData(d)); case RelativeSourceMode.FindAncestor: d = FindAncestorOfType(_relativeSource.AncestorType, _relativeSource.AncestorLevel, d, args.IsTracing); if (d == null) { return(DependencyProperty.UnsetValue); // we fell off the tree } break; default: return(null); } if (args.IsTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.RelativeSource( _relativeSource.Mode, TraceData.Identify(d))); } return(d); }
/// <summary> Returns the referenced object. </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> /// <exception cref="ArgumentNullException"> d is a null reference </exception> internal override object GetObject(DependencyObject d, ObjectRefArgs args) { return(GetDataObjectImpl(d, args)); }
//------------------------------------------------------ // // Public Methods // //------------------------------------------------------ /// <summary> Returns the referenced object. </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> internal override object GetObject(DependencyObject d, ObjectRefArgs args) { if (d == null) { throw new ArgumentNullException("d"); } object o = null; if (args.ResolveNamesInTemplate) { // look in container's template (if any) first FrameworkElement fe = d as FrameworkElement; if (fe != null && fe.TemplateInternal != null) { o = Helper.FindNameInTemplate(_name, d); if (args.IsTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.ElementNameQueryTemplate( _name, TraceData.Identify(d))); } } if (o == null) { args.NameResolvedInOuterScope = true; } } FrameworkObject fo = new FrameworkObject(d); while (o == null && fo.DO != null) { DependencyObject scopeOwner; o = fo.FindName(_name, out scopeOwner); // if the original element is a scope owner, supports IComponentConnector, // and has a parent, don't use the result of FindName. The // element is probably an instance of a Xaml-subclassed control; // we want to resolve the name starting in the next outer scope. // (bug 1669408) // Also, if the element's NavigationService property is locally // set, the element is the root of a navigation and should use the // inner scope (bug 1765041) if (d == scopeOwner && d is IComponentConnector && d.ReadLocalValue(System.Windows.Navigation.NavigationService.NavigationServiceProperty) == DependencyProperty.UnsetValue) { DependencyObject parent = LogicalTreeHelper.GetParent(d); if (parent == null) { parent = Helper.FindMentor(d.InheritanceContext); } if (parent != null) { o = null; fo.Reset(parent); continue; } } if (args.IsTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.ElementNameQuery( _name, TraceData.Identify(fo.DO))); } if (o == null) { args.NameResolvedInOuterScope = true; // move to the next outer namescope. // First try TemplatedParent of the scope owner. FrameworkObject foScopeOwner = new FrameworkObject(scopeOwner); DependencyObject dd = foScopeOwner.TemplatedParent; // if that doesn't work, we could be at the top of // generated content for an ItemsControl. If so, use // the (visual) parent - a panel. if (dd == null) { Panel panel = fo.FrameworkParent.DO as Panel; if (panel != null && panel.IsItemsHost) { dd = panel; } } // if the logical parent is a ContentControl whose content // points right back, move to the ContentControl. This is the // m---- equivalent of having the ContentControl as the TemplatedParent. // (The InheritanceBehavior clause prevents this for cases where the // parent ContentControl imposes a barrier, e.g. Frame) if (dd == null && scopeOwner == null) { ContentControl cc = LogicalTreeHelper.GetParent(fo.DO) as ContentControl; if (cc != null && cc.Content == fo.DO && cc.InheritanceBehavior == InheritanceBehavior.Default) { dd = cc; } } // next, see if we're in a logical tree attached directly // to a ContentPresenter. This is the m---- equivalent of // having the ContentPresenter as the TemplatedParent. if (dd == null && scopeOwner == null) { // go to the top of the logical subtree DependencyObject parent; for (dd = fo.DO;;) { parent = LogicalTreeHelper.GetParent(dd); if (parent == null) { parent = Helper.FindMentor(dd.InheritanceContext); } if (parent == null) { break; } dd = parent; } // if it's attached to a ContentPresenter, move to the CP ContentPresenter cp = VisualTreeHelper.IsVisualType(dd) ? VisualTreeHelper.GetParent(dd) as ContentPresenter : null; dd = (cp != null && cp.TemplateInternal.CanBuildVisualTree) ? cp : null; } fo.Reset(dd); } } if (o == null) { o = DependencyProperty.UnsetValue; args.NameResolvedInOuterScope = false; } return(o); }
// try to get information from the tree context (parent, root, etc.) // If everything succeeds, activate the binding. // If anything fails in a way that might succeed after further layout, // just return (with status == Unattached). The binding engine will try // again later. For hard failures, set an error status; no more chances. // During the "last chance" attempt, treat all failures as "hard". void AttachToContext(AttachAttempt attempt) { // if the target has been GC'd, just give up DependencyObject target = TargetElement; if (target == null) return; // status will be Detached bool isExtendedTraceEnabled = TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.AttachToContext); bool traceObjectRef = TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.SourceLookup); // certain features should never be tried on the first attempt, as // they certainly require at least one layout pass if (attempt == AttachAttempt.First) { // relative source with ancestor lookup ObjectRef or = ParentBinding.SourceReference; if (or != null && or.TreeContextIsRequired(target)) { if (isExtendedTraceEnabled) { TraceData.Trace(TraceEventType.Warning, TraceData.SourceRequiresTreeContext( TraceData.Identify(this), or.Identify())); } return; } } bool lastChance = (attempt == AttachAttempt.Last); if (isExtendedTraceEnabled) { TraceData.Trace(TraceEventType.Warning, TraceData.AttachToContext( TraceData.Identify(this), lastChance ? " (last chance)" : String.Empty)); } // if the path has unresolved type names, the parser needs namesapce // information to resolve them. See XmlTypeMapper.GetTypeFromName. // Ignore this requirement during the last chance, and just let // GetTypeFromName fail if it wants to. if (!lastChance && ParentBinding.TreeContextIsRequired) { if (target.GetValue(XmlAttributeProperties.XmlnsDictionaryProperty) == null || target.GetValue(XmlAttributeProperties.XmlNamespaceMapsProperty) == null) { if (isExtendedTraceEnabled) { TraceData.Trace(TraceEventType.Warning, TraceData.PathRequiresTreeContext( TraceData.Identify(this), ParentBinding.Path.Path)); } return; } } // if the binding uses a mentor, check that it exists DependencyObject mentor = !UsingMentor ? target : Helper.FindMentor(target); if (mentor == null) { if (isExtendedTraceEnabled) { TraceData.Trace(TraceEventType.Warning, TraceData.NoMentorExtended( TraceData.Identify(this))); } if (lastChance) { SetStatus(BindingStatusInternal.PathError); if (TraceData.IsEnabled) { TraceData.Trace(TraceEventType.Error, TraceData.NoMentor, this); } } return; } // determine the element whose DataContext governs this BindingExpression DependencyObject contextElement = null; // no context element bool contextElementFound = true; if (ParentBinding.SourceReference == null) { contextElement = mentor; // usually the mentor/target element // special cases: // 1. if target property is DataContext, use the target's parent. // This enables <X DataContext="{Binding...}"/> and // 2. if the target is ContentPresenter and the target property // is Content, use the parent. This enables // <ContentPresenter Content="{Binding...}"/> // 3. if target is CVS, and its inheritance context was set // via DataContext, use the mentor's parent. This enables // <X.DataContext> <CollectionViewSource Source={Binding ...}/> CollectionViewSource cvs; if (TargetProperty == FrameworkElement.DataContextProperty || (TargetProperty == ContentPresenter.ContentProperty && target is ContentPresenter) || (UsingMentor && (cvs = target as CollectionViewSource) != null && cvs.PropertyForInheritanceContext == FrameworkElement.DataContextProperty) ) { contextElement = FrameworkElement.GetFrameworkParent(contextElement); contextElementFound = (contextElement != null); } } else { RelativeObjectRef ror = ParentBinding.SourceReference as RelativeObjectRef; if (ror != null && ror.ReturnsDataContext) { object o = ror.GetObject(mentor, new ObjectRefArgs() { IsTracing = traceObjectRef}); contextElement = o as DependencyObject; // ref to another element's DataContext contextElementFound = (o != DependencyProperty.UnsetValue); } } if (isExtendedTraceEnabled) { TraceData.Trace(TraceEventType.Warning, TraceData.ContextElement( TraceData.Identify(this), TraceData.Identify(contextElement), contextElementFound ? "OK" : "error")); } // if we need a context element, check that we found it if (!contextElementFound) { if (lastChance) { SetStatus(BindingStatusInternal.PathError); if (TraceData.IsEnabled) { TraceData.Trace(TraceEventType.Error, TraceData.NoDataContext, this); } } return; } // determine the source object, from which the path evaluation starts object source; ObjectRef sourceRef; if (contextElement != null) { source = contextElement.GetValue(FrameworkElement.DataContextProperty); // if the data context is default null, try again later; future // layout may change the inherited value. // Ignore this requirement during the last chance, and just let // the binding to null DataContext proceed. if (source == null && !lastChance && !HasLocalDataContext(contextElement)) { if (isExtendedTraceEnabled) { TraceData.Trace(TraceEventType.Warning, TraceData.NullDataContext( TraceData.Identify(this))); } return; } } else if ((sourceRef = ParentBinding.SourceReference) != null) { ObjectRefArgs args = new ObjectRefArgs() { IsTracing = traceObjectRef, ResolveNamesInTemplate = ResolveNamesInTemplate, }; source = sourceRef.GetDataObject(mentor, args); // check that the source could be found if (source == DependencyProperty.UnsetValue) { if (lastChance) { SetStatus(BindingStatusInternal.PathError); if (TraceData.IsEnabled) { TraceData.Trace(TraceLevel, TraceData.NoSource(sourceRef), this); } } return; } else if (!lastChance && args.NameResolvedInOuterScope) { // if ElementName resolved in an outer scope, it's possible // that future work might add the name to an inner scope. // Schedule a task to check this. Engine.AddTask(this, TaskOps.VerifySourceReference); } } else { // we get here only if we need ambient data context, but there // is no context element. E.g. binding the DataContext property // of an element with no parent. Just use null. source = null; } // if we get this far, all the ingredients for a successful binding // are present. Remember what we've found and activate the binding. if (contextElement != null) _ctxElement = new WeakReference(contextElement); // attach to context element ChangeWorkerSources(null, 0); if (!UseDefaultValueConverter) { Converter = ParentBinding.Converter; if (Converter == null) { throw new InvalidOperationException(SR.Get(SRID.MissingValueConverter)); // report instead of throw? } } // join the right binding group (if any) JoinBindingGroup(IsReflective, contextElement); SetStatus(BindingStatusInternal.Inactive); // inner BindingExpressions of PriorityBindingExpressions may not need to be activated if (IsInPriorityBindingExpression) ParentPriorityBindingExpression.InvalidateChild(this); else // singular BindingExpressions and those in MultiBindingExpressions should always activate Activate(source); GC.KeepAlive(target); // keep target alive during activation (bug 956831) }
void IDataBindEngineClient.VerifySourceReference(bool lastChance) { DependencyObject target = TargetElement; if (target == null) return; // binding was detached since scheduling this task ObjectRef sourceRef = ParentBinding.SourceReference; DependencyObject mentor = !UsingMentor ? target : Helper.FindMentor(target); ObjectRefArgs args = new ObjectRefArgs() { ResolveNamesInTemplate = ResolveNamesInTemplate, }; object source = sourceRef.GetDataObject(mentor, args); if (source != DataItem) { // the source reference resolves differently from before, so // re-attach to the tree context AttachToContext(lastChance ? AttachAttempt.Last : AttachAttempt.Again); } }
//------------------------------------------------------ // // Public Methods // //------------------------------------------------------ /// <summary> Returns the referenced object. </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> internal override object GetObject(DependencyObject d, ObjectRefArgs args) { return((_element != null) ? _element.Target : _object); }
//------------------------------------------------------ // // Public Methods // //----------------------------------------------------- /// <summary> Returns the referenced object. </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> internal override object GetObject(DependencyObject d, ObjectRefArgs args) { return (_element != null) ? _element.Target : _object; }
//------------------------------------------------------ // // Public Methods // //----------------------------------------------------- /// <summary> Returns the referenced object. </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> internal virtual object GetObject(DependencyObject d, ObjectRefArgs args) { return null; }
private object GetDataObjectImpl(DependencyObject d, ObjectRefArgs args) { if (d == null) return null; switch (_relativeSource.Mode) { case RelativeSourceMode.Self: break; // nothing to do case RelativeSourceMode.TemplatedParent: d = Helper.GetTemplatedParent(d); break; case RelativeSourceMode.PreviousData: return GetPreviousData(d); case RelativeSourceMode.FindAncestor: d = FindAncestorOfType(_relativeSource.AncestorType, _relativeSource.AncestorLevel, d, args.IsTracing); if (d == null) { return DependencyProperty.UnsetValue; // we fell off the tree } break; default: return null; } if (args.IsTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.RelativeSource( _relativeSource.Mode, TraceData.Identify(d))); } return d; }
/// <summary> Returns the data object associated with the referenced object. /// Often this is the same as the referenced object. /// </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> /// <exception cref="ArgumentNullException"> d is a null reference </exception> internal override object GetDataObject(DependencyObject d, ObjectRefArgs args) { object o = GetDataObjectImpl(d, args); DependencyObject el = o as DependencyObject; if (el != null && ReturnsDataContext) { // for generated wrappers, use the ItemForContainer property instead // of DataContext, since it's always set by the generator o = el.GetValue(ItemContainerGenerator.ItemForItemContainerProperty); if (o == null) o = el.GetValue(FrameworkElement.DataContextProperty); } return o; }
/// <summary> Returns the referenced object. </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> /// <exception cref="ArgumentNullException"> d is a null reference </exception> internal override object GetObject(DependencyObject d, ObjectRefArgs args) { return GetDataObjectImpl(d, args); }
//----------------------------------------------------- // // Public Methods // //------------------------------------------------------ /// <summary> Returns the referenced object. </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> internal override object GetObject(DependencyObject d, ObjectRefArgs args) { if (d == null) throw new ArgumentNullException("d"); object o = null; if (args.ResolveNamesInTemplate) { // look in container's template (if any) first FrameworkElement fe = d as FrameworkElement; if (fe != null && fe.TemplateInternal != null) { o = Helper.FindNameInTemplate(_name, d); if (args.IsTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.ElementNameQueryTemplate( _name, TraceData.Identify(d))); } } if (o == null) { args.NameResolvedInOuterScope = true; } } FrameworkObject fo = new FrameworkObject(d); while (o == null && fo.DO != null) { DependencyObject scopeOwner; o = fo.FindName(_name, out scopeOwner); // if the original element is a scope owner, supports IComponentConnector, // and has a parent, don't use the result of FindName. The // element is probably an instance of a Xaml-subclassed control; // we want to resolve the name starting in the next outer scope. // (bug 1669408) // Also, if the element's NavigationService property is locally // set, the element is the root of a navigation and should use the // inner scope (bug 1765041) if (d == scopeOwner && d is IComponentConnector && d.ReadLocalValue(System.Windows.Navigation.NavigationService.NavigationServiceProperty) == DependencyProperty.UnsetValue) { DependencyObject parent = LogicalTreeHelper.GetParent(d); if (parent == null) { parent = Helper.FindMentor(d.InheritanceContext); } if (parent != null) { o = null; fo.Reset(parent); continue; } } if (args.IsTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.ElementNameQuery( _name, TraceData.Identify(fo.DO))); } if (o == null) { args.NameResolvedInOuterScope = true; // move to the next outer namescope. // First try TemplatedParent of the scope owner. FrameworkObject foScopeOwner = new FrameworkObject(scopeOwner); DependencyObject dd = foScopeOwner.TemplatedParent; // if that doesn't work, we could be at the top of // generated content for an ItemsControl. If so, use // the (visual) parent - a panel. if (dd == null) { Panel panel = fo.FrameworkParent.DO as Panel; if (panel != null && panel.IsItemsHost) { dd = panel; } } // next, see if we're in a logical tree attached directly // to a ContentPresenter. This is the m---- equivalent of // having the ContentPresenter as the TemplatedParent. if (dd == null && scopeOwner == null) { // go to the top of the logical subtree DependencyObject parent; for (dd = fo.DO;;) { parent = LogicalTreeHelper.GetParent(dd); if (parent == null) { parent = Helper.FindMentor(dd.InheritanceContext); } if (parent == null) break; dd = parent; } // if it's attached to a ContentPresenter, move to the CP ContentPresenter cp = VisualTreeHelper.IsVisualType(dd) ? VisualTreeHelper.GetParent(dd) as ContentPresenter : null; dd = (cp != null && cp.TemplateInternal.CanBuildVisualTree) ? cp : null; } fo.Reset(dd); } } if (o == null) { o = DependencyProperty.UnsetValue; args.NameResolvedInOuterScope = false; } return o; }
//------------------------------------------------------ // // Public Methods // //------------------------------------------------------ /// <summary> Returns the referenced object. </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> internal virtual object GetObject(DependencyObject d, ObjectRefArgs args) { return(null); }
/// <summary> Returns the data object associated with the referenced object. /// Often this is the same as the referenced object. /// </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> internal virtual object GetDataObject(DependencyObject d, ObjectRefArgs args) { return GetObject(d, args); }
/// <summary> Returns the data object associated with the referenced object. /// Often this is the same as the referenced object. /// </summary> /// <param name="d">Element defining context for the reference. </param> /// <param name="args">See ObjectRefArgs </param> internal virtual object GetDataObject(DependencyObject d, ObjectRefArgs args) { return(GetObject(d, args)); }
// Token: 0x060075FB RID: 30203 RVA: 0x0021A3F0 File Offset: 0x002185F0 internal override object GetObject(DependencyObject d, ObjectRefArgs args) { if (d == null) { throw new ArgumentNullException("d"); } object obj = null; if (args.ResolveNamesInTemplate) { FrameworkElement frameworkElement = d as FrameworkElement; if (frameworkElement != null && frameworkElement.TemplateInternal != null) { obj = Helper.FindNameInTemplate(this._name, d); if (args.IsTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.ElementNameQueryTemplate(new object[] { this._name, TraceData.Identify(d) })); } } if (obj == null) { args.NameResolvedInOuterScope = true; } } FrameworkObject frameworkObject = new FrameworkObject(d); while (obj == null && frameworkObject.DO != null) { DependencyObject dependencyObject; obj = frameworkObject.FindName(this._name, out dependencyObject); if (d == dependencyObject && d is IComponentConnector && d.ReadLocalValue(NavigationService.NavigationServiceProperty) == DependencyProperty.UnsetValue) { DependencyObject dependencyObject2 = LogicalTreeHelper.GetParent(d); if (dependencyObject2 == null) { dependencyObject2 = Helper.FindMentor(d.InheritanceContext); } if (dependencyObject2 != null) { obj = null; frameworkObject.Reset(dependencyObject2); continue; } } if (args.IsTracing) { TraceData.Trace(TraceEventType.Warning, TraceData.ElementNameQuery(new object[] { this._name, TraceData.Identify(frameworkObject.DO) })); } if (obj == null) { args.NameResolvedInOuterScope = true; FrameworkObject frameworkObject2 = new FrameworkObject(dependencyObject); DependencyObject dependencyObject3 = frameworkObject2.TemplatedParent; if (dependencyObject3 == null) { Panel panel = frameworkObject.FrameworkParent.DO as Panel; if (panel != null && panel.IsItemsHost) { dependencyObject3 = panel; } } if (dependencyObject3 == null && dependencyObject == null) { ContentControl contentControl = LogicalTreeHelper.GetParent(frameworkObject.DO) as ContentControl; if (contentControl != null && contentControl.Content == frameworkObject.DO && contentControl.InheritanceBehavior == InheritanceBehavior.Default) { dependencyObject3 = contentControl; } } if (dependencyObject3 == null && dependencyObject == null) { dependencyObject3 = frameworkObject.DO; for (;;) { DependencyObject dependencyObject4 = LogicalTreeHelper.GetParent(dependencyObject3); if (dependencyObject4 == null) { dependencyObject4 = Helper.FindMentor(dependencyObject3.InheritanceContext); } if (dependencyObject4 == null) { break; } dependencyObject3 = dependencyObject4; } ContentPresenter contentPresenter = VisualTreeHelper.IsVisualType(dependencyObject3) ? (VisualTreeHelper.GetParent(dependencyObject3) as ContentPresenter) : null; dependencyObject3 = ((contentPresenter != null && contentPresenter.TemplateInternal.CanBuildVisualTree) ? contentPresenter : null); } frameworkObject.Reset(dependencyObject3); } } if (obj == null) { obj = DependencyProperty.UnsetValue; args.NameResolvedInOuterScope = false; } return(obj); }