/// <summary> /// Return the source of the value for the given property. /// </summary> public static ValueSource GetValueSource(DependencyObject dependencyObject, DependencyProperty dependencyProperty) { if (dependencyObject == null) { throw new ArgumentNullException(nameof(dependencyObject)); } if (dependencyProperty == null) { throw new ArgumentNullException(nameof(dependencyProperty)); } dependencyObject.VerifyAccess(); bool hasModifiers, isExpression, isAnimated, isCoerced, isCurrent; BaseValueSourceInternal source = dependencyObject.GetValueSource(dependencyProperty, null, out hasModifiers, out isExpression, out isAnimated, out isCoerced, out isCurrent); return(new ValueSource(source, isExpression, isAnimated, isCoerced, isCurrent)); }
/// <summary>Returns a structure that reports various metadata and property system characteristics of a specified dependency property on a particular <see cref="T:System.Windows.DependencyObject" />.</summary> /// <param name="dependencyObject">The element that contains the <paramref name="dependencyProperty" /> to report information for.</param> /// <param name="dependencyProperty">The identifier for the dependency property to report information for.</param> /// <returns>A <see cref="T:System.Windows.ValueSource" /> structure that reports the specific information.</returns> // Token: 0x060003B9 RID: 953 RVA: 0x0000A968 File Offset: 0x00008B68 public static ValueSource GetValueSource(DependencyObject dependencyObject, DependencyProperty dependencyProperty) { if (dependencyObject == null) { throw new ArgumentNullException("dependencyObject"); } if (dependencyProperty == null) { throw new ArgumentNullException("dependencyProperty"); } dependencyObject.VerifyAccess(); bool flag; bool isExpression; bool isAnimated; bool isCoerced; bool isCurrent; BaseValueSourceInternal valueSource = dependencyObject.GetValueSource(dependencyProperty, null, out flag, out isExpression, out isAnimated, out isCoerced, out isCurrent); return(new ValueSource(valueSource, isExpression, isAnimated, isCoerced, isCurrent)); }
/// <summary> /// Invoked when logical parent is changed. This just /// sets the parent pointer. /// </summary> /// <remarks> /// A parent change is considered catastrohpic and results in a large /// amount of invalidations and tree traversals. <cref see="DependencyFastBuild"/> /// is recommended to reduce the work necessary to build a tree /// </remarks> /// <param name="newParent"> /// New parent that was set /// </param> internal void ChangeLogicalParent(DependencyObject newParent) { /////////////////// // OnNewParent: /////////////////// // // -- Approved By The Core Team -- // // Do not allow foreign threads to change the tree. // (This is a noop if this object is not assigned to a Dispatcher.) // // We also need to ensure that the tree is homogenous with respect // to the dispatchers that the elements belong to. // this.VerifyAccess(); if (newParent != null) { newParent.VerifyAccess(); } // Logical Parent must first be dropped before you are attached to a newParent // This mitigates illegal tree state caused by logical child stealing as illustrated in bug 970706 if (_parent != null && newParent != null && _parent != newParent) { throw new System.InvalidOperationException(SR.Get(SRID.HasLogicalParent)); } // Trivial check to avoid loops if (newParent == this) { throw new System.InvalidOperationException(SR.Get(SRID.CannotBeSelfParent)); } // Logical Parent implies no InheritanceContext if (newParent != null) { ClearInheritanceContext(); } IsParentAnFE = newParent is FrameworkElement; DependencyObject oldParent = _parent; OnNewParent(newParent); // Update Has[Loaded/Unloaded]Handler Flags BroadcastEventHelper.AddOrRemoveHasLoadedChangeHandlerFlag(this, oldParent, newParent); /////////////////// // OnParentChanged: /////////////////// // Invalidate relevant properties for this subtree DependencyObject parent = (newParent != null) ? newParent : oldParent; TreeWalkHelper.InvalidateOnTreeChange(/* fe = */ this, /* fce = */ null, parent, (newParent != null)); // If no one has called BeginInit then mark the element initialized and fire Initialized event // (non-parser programmatic tree building scenario) TryFireInitialized(); }
/// <summary> /// Return the source of the value for the given property. /// </summary> public static ValueSource GetValueSource(DependencyObject dependencyObject, DependencyProperty dependencyProperty) { if (dependencyObject == null) throw new ArgumentNullException("dependencyObject"); if (dependencyProperty == null) throw new ArgumentNullException("dependencyProperty"); dependencyObject.VerifyAccess(); bool hasModifiers, isExpression, isAnimated, isCoerced, isCurrent; BaseValueSourceInternal source = dependencyObject.GetValueSource(dependencyProperty, null, out hasModifiers, out isExpression, out isAnimated, out isCoerced, out isCurrent); return new ValueSource(source, isExpression, isAnimated, isCoerced, isCurrent); }
internal void ChangeLogicalParent(DependencyObject newParent) { this.VerifyAccess(); if (newParent != null) newParent.VerifyAccess(); if (this._parent != null && newParent != null && this._parent != newParent) throw new InvalidOperationException(System.Windows.SR.Get("HasLogicalParent")); if (newParent == this) throw new InvalidOperationException(System.Windows.SR.Get("CannotBeSelfParent")); if (newParent != null) this.ClearInheritanceContext(); this.IsParentAnFE = newParent is FrameworkElement; DependencyObject oldParent = this._parent; this.OnNewParent(newParent); BroadcastEventHelper.AddOrRemoveHasLoadedChangeHandlerFlag((DependencyObject) this, oldParent, newParent); TreeWalkHelper.InvalidateOnTreeChange(this, (FrameworkContentElement) null, newParent != null ? newParent : oldParent, newParent != null); this.TryFireInitialized(); }
//------------------------------------------------------ // // Internal Methods // //----------------------------------------------------- /// <summary> /// Attach the binding expression to the given target object and property. /// </summary> internal void Attach(DependencyObject target, DependencyProperty dp) { // make sure we're on the right thread to access the target if (target != null) { target.VerifyAccess(); } IsAttaching = true; AttachOverride(target, dp); IsAttaching = false; }
/// <summary> /// Returns null if the given element is null, otherwise visual or visual3D /// will be the strong visual type on exit. /// /// Throws an exception if element is a non-Visual type. /// </summary> internal static void AsVisual(DependencyObject element, out Visual visual, out Visual3D visual3D) { bool castSucceeded = AsVisualHelper(element, out visual, out visual3D); if (element != null) { if (!castSucceeded) { throw new System.InvalidOperationException(SR.Get(SRID.Visual_NotAVisual, element.GetType())); } Debug.Assert(castSucceeded && ((visual == null) != (visual3D == null)), "Either visual or visual3D exclusively should be non-null."); element.VerifyAccess(); } else { Debug.Assert(!castSucceeded && visual == null && visual3D == null, "How did the cast succeed if the element was null going in?"); } }
/// <summary> /// Throws if the given element is not a Visual or Visual3D /// or if the Visual is on the wrong thread. /// </summary> private static void EnsureVisual(DependencyObject element, bool allowNull) { if (element == null) { if (!allowNull) { throw new ArgumentNullException("element"); } return; } // if (!(element is Visual || element is Visual3D)) { throw new ArgumentException(SR.Get(SRID.Visual_NotAVisual)); } element.VerifyAccess(); }
/// <summary> /// Invoked when logical parent is changed. This just /// sets the parent pointer. /// </summary> /// <remarks> /// A parent change is considered catastrohpic and results in a large /// amount of invalidations and tree traversals. <cref see="DependencyFastBuild"/> /// is recommended to reduce the work necessary to build a tree /// </remarks> /// <param name="newParent"> /// New parent that was set /// </param> internal void ChangeLogicalParent(DependencyObject newParent) { /////////////////// // OnNewParent: /////////////////// // // -- Approved By The Core Team -- // // Do not allow foreign threads to change the tree. // (This is a noop if this object is not assigned to a Dispatcher.) // // We also need to ensure that the tree is homogenous with respect // to the dispatchers that the elements belong to. // this.VerifyAccess(); if(newParent != null) { newParent.VerifyAccess(); } // Logical Parent must first be dropped before you are attached to a newParent // This mitigates illegal tree state caused by logical child stealing as illustrated in bug 970706 if (_parent != null && newParent != null && _parent != newParent) { throw new System.InvalidOperationException(SR.Get(SRID.HasLogicalParent)); } // Trivial check to avoid loops if (newParent == this) { throw new System.InvalidOperationException(SR.Get(SRID.CannotBeSelfParent)); } // Logical Parent implies no InheritanceContext if (newParent != null) { ClearInheritanceContext(); } IsParentAnFE = newParent is FrameworkElement; DependencyObject oldParent = _parent; OnNewParent(newParent); // Update Has[Loaded/Unloaded]Handler Flags BroadcastEventHelper.AddOrRemoveHasLoadedChangeHandlerFlag(this, oldParent, newParent); // Fire Loaded and Unloaded Events BroadcastEventHelper.BroadcastLoadedOrUnloadedEvent(this, oldParent, newParent); /////////////////// // OnParentChanged: /////////////////// // Invalidate relevant properties for this subtree DependencyObject parent = (newParent != null) ? newParent : oldParent; TreeWalkHelper.InvalidateOnTreeChange(/* fe = */ null, /* fce = */ this, parent, (newParent != null)); // If no one has called BeginInit then mark the element initialized and fire Initialized event // (non-parser programmatic tree building scenario) TryFireInitialized(); }