/// <summary> /// You have a new InheritanceContext /// </summary> /// <remarks> /// This is to solve the case of programmatically creating a VisualBrush or BitmapCacheBrush /// with an element in it and the element not getting Initialized. /// </remarks> internal override void AddInheritanceContext(DependencyObject context, DependencyProperty property) { base.AddInheritanceContext(context, property); // Initialize, if not already done TryFireInitialized(); // accept the new inheritance context provided that // a) the requested link uses VisualBrush.Visual or BitmapCacheBrush.TargetProperty // b) this element has no visual or logical parent // c) the context does not introduce a cycle if ((property == VisualBrush.VisualProperty || property == BitmapCacheBrush.TargetProperty) && FrameworkElement.GetFrameworkParent(this) == null //!FrameworkObject.IsEffectiveAncestor(this, context, property)) && !FrameworkObject.IsEffectiveAncestor(this, context)) { //FrameworkObject.Log("+ {0}", FrameworkObject.LogIC(context, property, this)); if (!HasMultipleInheritanceContexts && InheritanceContext == null) { // first request - accept the new inheritance context InheritanceContextField.SetValue(this, context); OnInheritanceContextChanged(EventArgs.Empty); } else if (InheritanceContext != null) { // second request - remove all context and enter "shared" mode InheritanceContextField.ClearValue(this); WriteInternalFlag2(InternalFlags2.HasMultipleInheritanceContexts, true); OnInheritanceContextChanged(EventArgs.Empty); } // else already in shared mode - ignore the request } }
/// <summary> /// This method is invoked when the Content property changes. /// </summary> /// <param name="oldContent">The old value of the Content property.</param> /// <param name="newContent">The new value of the Content property.</param> protected virtual void OnContentChanged(object oldContent, object newContent) { // Remove the old content child RemoveLogicalChild(oldContent); // if Content should not be treated as a logical child, there's // nothing to do if (ContentIsNotLogical) { return; } DependencyObject d = newContent as DependencyObject; if (d != null) { DependencyObject logicalParent = LogicalTreeHelper.GetParent(d); if (logicalParent != null) { if (TemplatedParent != null && FrameworkObject.IsEffectiveAncestor(logicalParent, this)) { // In the case that this ContentControl 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. LogicalTreeHelper.RemoveLogicalChild(logicalParent, newContent); } } } // Add the new content child AddLogicalChild(newContent); }
/// <summary> Called when the <see cref="P:System.Windows.Controls.ContentControl.Content" /> property changes. </summary> /// <param name="oldContent">The old value of the <see cref="P:System.Windows.Controls.ContentControl.Content" /> property.</param> /// <param name="newContent">The new value of the <see cref="P:System.Windows.Controls.ContentControl.Content" /> property.</param> // Token: 0x060043DB RID: 17371 RVA: 0x00135DDC File Offset: 0x00133FDC protected virtual void OnContentChanged(object oldContent, object newContent) { base.RemoveLogicalChild(oldContent); if (this.ContentIsNotLogical) { return; } DependencyObject dependencyObject = newContent as DependencyObject; if (dependencyObject != null) { DependencyObject parent = LogicalTreeHelper.GetParent(dependencyObject); if (parent != null) { if (base.TemplatedParent != null && FrameworkObject.IsEffectiveAncestor(parent, this)) { return; } LogicalTreeHelper.RemoveLogicalChild(parent, newContent); } } base.AddLogicalChild(newContent); }