internal static FrameworkObject GetContainingFrameworkElement(DependencyObject current) { var fo = new FrameworkObject(current); while (!fo.IsValid && fo.DependencyObject != null) { // The current object is neither a FrameworkElement nor a // FrameworkContentElement. We will now walk the "core" // tree looking for one. Visual visual; Visual3D visual3D; ContentElement ce; if ((visual = fo.DependencyObject as Visual) != null) { fo.Reset(VisualTreeHelper.GetParent(visual)); } else if ((ce = fo.DependencyObject as ContentElement) != null) { fo.Reset(ContentOperations.GetParent(ce)); } else if ((visual3D = fo.DependencyObject as Visual3D) != null) { fo.Reset(VisualTreeHelper.GetParent(visual3D)); } else { // The parent could be an application. fo.Reset(null); } } return(fo); }
/// <summary> /// This method is invoked when the Child property changes. /// http://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Controls/ContentControl.cs,262 /// </summary> /// <param name="oldChild">The old value of the Child property.</param> /// <param name="newChild">The new value of the Child property.</param> protected virtual void OnChildChanged(BaseBox oldChild, BaseBox newChild) { this.RemoveLogicalChild(oldChild); if (newChild != null) { var logicalParent = LogicalTreeHelper.GetParent(newChild); if (logicalParent != null) { if (this.TemplatedParent != null && FrameworkObject.IsEffectiveAncestor(logicalParent, this)) { // In the case that this SpinnerDecorator belongs in a parent template // and represents the content of a parent, we do not wish to change // the logical ancestry of the content. return; } else { // If the new content was previously hooked up to the logical // tree then we sever it from the old parent. var message = "Cannot add child that already belongs to a parent.\r\n" + "Fixing this requires more source diving than I feel like right now.\r\n" + "Waiting to see if it becomes a problem"; throw new NotSupportedException(message); //// LogicalTreeHelper.RemoveLogicalChild(logicalParent, newChild); } } } // Add the new content child this.AddLogicalChild(newChild); }
//// internal bool ThisHasLoadedChangeEventHandler //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.ThisHasLoadedChangeEventHandler; //// } //// else if (this.IsFCE) //// { //// return this._fce.ThisHasLoadedChangeEventHandler; //// } //// else //// { //// return false; //// } //// } //// } //// internal bool SubtreeHasLoadedChangeHandler //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.SubtreeHasLoadedChangeHandler; //// } //// else if (this.IsFCE) //// { //// return this._fce.SubtreeHasLoadedChangeHandler; //// } //// else //// { //// return false; //// } //// } //// set //// { //// if (this.IsFE) //// { //// this._fe.SubtreeHasLoadedChangeHandler = value; //// } //// else if (this.IsFCE) //// { //// this._fce.SubtreeHasLoadedChangeHandler = value; //// } //// } //// } //// internal InheritanceBehavior InheritanceBehavior //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.InheritanceBehavior; //// } //// else if (this.IsFCE) //// { //// return this._fce.InheritanceBehavior; //// } //// else //// { //// return InheritanceBehavior.Default; //// } //// } //// } //// internal bool StoresParentTemplateValues //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.StoresParentTemplateValues; //// } //// else if (this.IsFCE) //// { //// return this._fce.StoresParentTemplateValues; //// } //// else //// { //// return false; //// } //// } //// set //// { //// if (this.IsFE) //// { //// this._fe.StoresParentTemplateValues = value; //// } //// else if (this.IsFCE) //// { //// this._fce.StoresParentTemplateValues = value; //// } //// } //// } //// internal bool HasResourceReference //// { //// /* not used (yet) //// get //// { //// if (IsFE) //// { //// return _fe.HasResourceReference; //// } //// else if (IsFCE) //// { //// return _fce.HasResourceReference; //// } //// else //// { //// return false; //// } //// } //// */ //// set //// { //// if (this.IsFE) //// { //// this._fe.HasResourceReference = value; //// } //// else if (this.IsFCE) //// { //// this._fce.HasResourceReference = value; //// } //// } //// } /* not used (yet) * internal bool HasStyleChanged * { * get * { * if (IsFE) * { * return _fe.HasStyleChanged; * } * else if (IsFCE) * { * return _fce.HasStyleChanged; * } * else * { * return false; * } * } * set * { * if (IsFE) * { * _fe.HasStyleChanged = value; * } * else if (IsFCE) * { * _fce.HasStyleChanged = value; * } * } * } */ //// internal bool HasTemplateChanged //// { //// /* not used (yet) //// get //// { //// if (IsFE) //// { //// return _fe.HasTemplateChanged; //// } //// else //// { //// return false; //// } //// } //// */ //// set //// { //// if (this.IsFE) //// { //// this._fe.HasTemplateChanged = value; //// } //// } //// } //// Says if there are any implicit styles in the ancestry //// internal bool ShouldLookupImplicitStyles //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.ShouldLookupImplicitStyles; //// } //// else if (this.IsFCE) //// { //// return this._fce.ShouldLookupImplicitStyles; //// } //// else //// { //// return false; //// } //// } //// set //// { //// if (this.IsFE) //// { //// this._fe.ShouldLookupImplicitStyles = value; //// } //// else if (this.IsFCE) //// { //// this._fce.ShouldLookupImplicitStyles = value; //// } //// } //// } internal static bool IsEffectiveAncestor(DependencyObject d1, DependencyObject d2) { for (var fo = new FrameworkObject(d2); fo.DependencyObject != null; fo.Reset(fo.EffectiveParent)) { if (ReferenceEquals(fo.DependencyObject, d1)) { return(true); } } return(false); }
internal static FrameworkObject GetContainingFrameworkElement(DependencyObject current) { FrameworkObject fo = new FrameworkObject(current); while (!fo.IsValid && fo.DependencyObject != null) { // The current object is neither a FrameworkElement nor a // FrameworkContentElement. We will now walk the "core" // tree looking for one. Visual visual; Visual3D visual3D; ContentElement ce; if ((visual = fo.DependencyObject as Visual) != null) { fo.Reset(VisualTreeHelper.GetParent(visual)); } else if ((ce = fo.DependencyObject as ContentElement) != null) { fo.Reset(ContentOperations.GetParent(ce)); } else if ((visual3D = fo.DependencyObject as Visual3D) != null) { fo.Reset(VisualTreeHelper.GetParent(visual3D)); } else { // The parent could be an application. fo.Reset(null); } } return fo; }
//// internal bool ThisHasLoadedChangeEventHandler //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.ThisHasLoadedChangeEventHandler; //// } //// else if (this.IsFCE) //// { //// return this._fce.ThisHasLoadedChangeEventHandler; //// } //// else //// { //// return false; //// } //// } //// } //// internal bool SubtreeHasLoadedChangeHandler //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.SubtreeHasLoadedChangeHandler; //// } //// else if (this.IsFCE) //// { //// return this._fce.SubtreeHasLoadedChangeHandler; //// } //// else //// { //// return false; //// } //// } //// set //// { //// if (this.IsFE) //// { //// this._fe.SubtreeHasLoadedChangeHandler = value; //// } //// else if (this.IsFCE) //// { //// this._fce.SubtreeHasLoadedChangeHandler = value; //// } //// } //// } //// internal InheritanceBehavior InheritanceBehavior //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.InheritanceBehavior; //// } //// else if (this.IsFCE) //// { //// return this._fce.InheritanceBehavior; //// } //// else //// { //// return InheritanceBehavior.Default; //// } //// } //// } //// internal bool StoresParentTemplateValues //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.StoresParentTemplateValues; //// } //// else if (this.IsFCE) //// { //// return this._fce.StoresParentTemplateValues; //// } //// else //// { //// return false; //// } //// } //// set //// { //// if (this.IsFE) //// { //// this._fe.StoresParentTemplateValues = value; //// } //// else if (this.IsFCE) //// { //// this._fce.StoresParentTemplateValues = value; //// } //// } //// } //// internal bool HasResourceReference //// { //// /* not used (yet) //// get //// { //// if (IsFE) //// { //// return _fe.HasResourceReference; //// } //// else if (IsFCE) //// { //// return _fce.HasResourceReference; //// } //// else //// { //// return false; //// } //// } //// */ //// set //// { //// if (this.IsFE) //// { //// this._fe.HasResourceReference = value; //// } //// else if (this.IsFCE) //// { //// this._fce.HasResourceReference = value; //// } //// } //// } /* not used (yet) internal bool HasStyleChanged { get { if (IsFE) { return _fe.HasStyleChanged; } else if (IsFCE) { return _fce.HasStyleChanged; } else { return false; } } set { if (IsFE) { _fe.HasStyleChanged = value; } else if (IsFCE) { _fce.HasStyleChanged = value; } } } */ //// internal bool HasTemplateChanged //// { //// /* not used (yet) //// get //// { //// if (IsFE) //// { //// return _fe.HasTemplateChanged; //// } //// else //// { //// return false; //// } //// } //// */ //// set //// { //// if (this.IsFE) //// { //// this._fe.HasTemplateChanged = value; //// } //// } //// } //// Says if there are any implicit styles in the ancestry //// internal bool ShouldLookupImplicitStyles //// { //// get //// { //// if (this.IsFE) //// { //// return this._fe.ShouldLookupImplicitStyles; //// } //// else if (this.IsFCE) //// { //// return this._fce.ShouldLookupImplicitStyles; //// } //// else //// { //// return false; //// } //// } //// set //// { //// if (this.IsFE) //// { //// this._fe.ShouldLookupImplicitStyles = value; //// } //// else if (this.IsFCE) //// { //// this._fce.ShouldLookupImplicitStyles = value; //// } //// } //// } internal static bool IsEffectiveAncestor(DependencyObject d1, DependencyObject d2) { for (FrameworkObject fo = new FrameworkObject(d2); fo.DependencyObject != null; fo.Reset(fo.EffectiveParent)) { if (ReferenceEquals(fo.DependencyObject, d1)) { return true; } } return false; }