Example #1
0
        /// <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
            }
        }
        //------------------------------------------------------
        //
        //  Internal Methods
        //
        //------------------------------------------------------


        /// <summary>
        ///     Returns true if the object provided is the immediate logical
        ///     child (if IncludeDescendants is false) or any logical child
        ///     (if IncludeDescendants is true).
        /// </summary>
        internal override bool IsBrowsable(DependencyObject d, DependencyProperty dp)
        {
            if (d == null)
            {
                throw new ArgumentNullException("d");
            }
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }

            DependencyObject walk      = d;
            Type             ownerType = dp.OwnerType;

            do
            {
                walk = FrameworkElement.GetFrameworkParent(walk);

                if (walk != null && ownerType.IsInstanceOfType(walk))
                {
                    return(true);
                }
            }while (_includeDescendants && walk != null);

            return(false);
        }
Example #3
0
        // Token: 0x06000302 RID: 770 RVA: 0x000084D8 File Offset: 0x000066D8
        internal override bool IsBrowsable(DependencyObject d, DependencyProperty dp)
        {
            if (d == null)
            {
                throw new ArgumentNullException("d");
            }
            if (dp == null)
            {
                throw new ArgumentNullException("dp");
            }
            DependencyObject dependencyObject = d;
            Type             ownerType        = dp.OwnerType;

            for (;;)
            {
                dependencyObject = FrameworkElement.GetFrameworkParent(dependencyObject);
                if (dependencyObject != null && ownerType.IsInstanceOfType(dependencyObject))
                {
                    break;
                }
                if (!this._includeDescendants || dependencyObject == null)
                {
                    return(false);
                }
            }
            return(true);
        }
Example #4
0
        // Invalidate all the properties that may have changed as a result of
        //  changing this element's parent in the logical (and sometimes visual tree.)
        internal FrugalObjectList <DependencyProperty> InvalidateTreeDependentProperties(TreeChangeInfo parentTreeState, bool isSelfInheritanceParent, bool wasSelfInheritanceParent)
        {
            AncestorChangeInProgress = true;

            InVisibilityCollapsedTree = false;  // False == we don't know whether we're in a visibility collapsed tree.

            if (parentTreeState.TopmostCollapsedParentNode == null)
            {
                // There is no ancestor node with Visibility=Collapsed.
                //  See if "fe" is the root of a collapsed subtree.
                if (Visibility == Visibility.Collapsed)
                {
                    // This is indeed the root of a collapsed subtree.
                    //  remember this information as we proceed on the tree walk.
                    parentTreeState.TopmostCollapsedParentNode = this;

                    // Yes, this FE node is in a visibility collapsed subtree.
                    InVisibilityCollapsedTree = true;
                }
            }
            else
            {
                // There is an ancestor node somewhere above us with
                //  Visibility=Collapsed.  We're in a visibility collapsed subtree.
                InVisibilityCollapsedTree = true;
            }


            try
            {
                // Style property is a special case of a non-inherited property that needs
                // invalidation for parent changes. Invalidate StyleProperty if it hasn't been
                // locally set because local value takes precedence over implicit references
                if (IsInitialized && !HasLocalStyle && (this != parentTreeState.Root))
                {
                    UpdateStyleProperty();
                }

                Style            selfStyle       = null;
                Style            selfThemeStyle  = null;
                DependencyObject templatedParent = null;

                int         childIndex         = -1;
                ChildRecord childRecord        = new ChildRecord();
                bool        isChildRecordValid = false;

                selfStyle       = Style;
                selfThemeStyle  = ThemeStyle;
                templatedParent = TemplatedParent;
                childIndex      = TemplateChildIndex;

                // StyleProperty could have changed during invalidation of ResourceReferenceExpressions if it
                // were locally set or during the invalidation of unresolved implicitly referenced style
                bool hasStyleChanged = HasStyleChanged;

                // Fetch selfStyle, hasStyleChanged and childIndex for the current node
                FrameworkElement.GetTemplatedParentChildRecord(templatedParent, childIndex, out childRecord, out isChildRecordValid);

                FrameworkElement        parentFE;
                FrameworkContentElement parentFCE;
                bool hasParent = FrameworkElement.GetFrameworkParent(this, out parentFE, out parentFCE);

                DependencyObject    parent = null;
                InheritanceBehavior parentInheritanceBehavior = InheritanceBehavior.Default;
                if (hasParent)
                {
                    if (parentFE != null)
                    {
                        parent = parentFE;
                        parentInheritanceBehavior = parentFE.InheritanceBehavior;
                    }
                    else
                    {
                        parent = parentFCE;
                        parentInheritanceBehavior = parentFCE.InheritanceBehavior;
                    }
                }

                if (!TreeWalkHelper.SkipNext(InheritanceBehavior) && !TreeWalkHelper.SkipNow(parentInheritanceBehavior))
                {
                    // Synchronize InheritanceParent
                    this.SynchronizeInheritanceParent(parent);
                }
                else if (!IsSelfInheritanceParent)
                {
                    // Set IsSelfInheritanceParet on the root node at a tree boundary
                    // so that all inheritable properties are cached on it.
                    SetIsSelfInheritanceParent();
                }

                // Loop through all cached inheritable properties for the parent to see if they should be invalidated.
                return(TreeWalkHelper.InvalidateTreeDependentProperties(parentTreeState, /* fe = */ this, /* fce = */ null, selfStyle, selfThemeStyle,
                                                                        ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent, wasSelfInheritanceParent));
            }
            finally
            {
                AncestorChangeInProgress  = false;
                InVisibilityCollapsedTree = false;  // 'false' just means 'we don't know' - see comment at definition of the flag.
            }
        }
Example #5
0
        // Invalidate all the properties that may have changed as a result of
        //  changing this element's parent in the logical (and sometimes visual tree.)
        internal FrugalObjectList <DependencyProperty> InvalidateTreeDependentProperties(TreeChangeInfo parentTreeState, bool isSelfInheritanceParent, bool wasSelfInheritanceParent)
        {
            AncestorChangeInProgress = true;


            try
            {
                // Style property is a special case of a non-inherited property that needs
                // invalidation for parent changes. Invalidate StyleProperty if it hasn't been
                // locally set because local value takes precedence over implicit references
                if (!HasLocalStyle && (this != parentTreeState.Root))
                {
                    UpdateStyleProperty();
                }

                Style            selfStyle       = null;
                Style            selfThemeStyle  = null;
                DependencyObject templatedParent = null;

                int         childIndex         = -1;
                ChildRecord childRecord        = new ChildRecord();
                bool        isChildRecordValid = false;

                selfStyle       = Style;
                selfThemeStyle  = ThemeStyle;
                templatedParent = TemplatedParent;
                childIndex      = TemplateChildIndex;

                // StyleProperty could have changed during invalidation of ResourceReferenceExpressions if it
                // were locally set or during the invalidation of unresolved implicitly referenced style
                bool hasStyleChanged = HasStyleChanged;

                // Fetch selfStyle, hasStyleChanged and childIndex for the current node
                FrameworkElement.GetTemplatedParentChildRecord(templatedParent, childIndex, out childRecord, out isChildRecordValid);

                FrameworkElement        parentFE;
                FrameworkContentElement parentFCE;
                bool hasParent = FrameworkElement.GetFrameworkParent(this, out parentFE, out parentFCE);

                DependencyObject    parent = null;
                InheritanceBehavior parentInheritanceBehavior = InheritanceBehavior.Default;
                if (hasParent)
                {
                    if (parentFE != null)
                    {
                        parent = parentFE;
                        parentInheritanceBehavior = parentFE.InheritanceBehavior;
                    }
                    else
                    {
                        parent = parentFCE;
                        parentInheritanceBehavior = parentFCE.InheritanceBehavior;
                    }
                }

                if (!TreeWalkHelper.SkipNext(InheritanceBehavior) && !TreeWalkHelper.SkipNow(parentInheritanceBehavior))
                {
                    // Synchronize InheritanceParent
                    this.SynchronizeInheritanceParent(parent);
                }
                else if (!IsSelfInheritanceParent)
                {
                    // Set IsSelfInheritanceParet on the root node at a tree boundary
                    // so that all inheritable properties are cached on it.
                    SetIsSelfInheritanceParent();
                }

                // Loop through all cached inheritable properties for the parent to see if they should be invalidated.
                return(TreeWalkHelper.InvalidateTreeDependentProperties(parentTreeState, /* fe = */ null, /* fce = */ this, selfStyle, selfThemeStyle,
                                                                        ref childRecord, isChildRecordValid, hasStyleChanged, isSelfInheritanceParent, wasSelfInheritanceParent));
            }
            finally
            {
                AncestorChangeInProgress = false;
            }
        }
Example #6
0
        // Token: 0x06000C6D RID: 3181 RVA: 0x0002EB78 File Offset: 0x0002CD78
        private static bool OnInheritablePropertyChanged(DependencyObject d, InheritablePropertyChangeInfo info, bool visitedViaVisualTree)
        {
            DependencyProperty  property = info.Property;
            EffectiveValueEntry oldEntry = info.OldEntry;
            EffectiveValueEntry newEntry = info.NewEntry;
            InheritanceBehavior inheritanceBehavior;
            bool flag  = TreeWalkHelper.IsInheritanceNode(d, property, out inheritanceBehavior);
            bool flag2 = TreeWalkHelper.IsForceInheritedProperty(property);

            if (!flag || (TreeWalkHelper.SkipNext(inheritanceBehavior) && !flag2))
            {
                return(inheritanceBehavior == InheritanceBehavior.Default || flag2);
            }
            PropertyMetadata metadata   = property.GetMetadata(d);
            EntryIndex       entryIndex = d.LookupEntry(property.GlobalIndex);

            if (!d.IsSelfInheritanceParent)
            {
                DependencyObject    frameworkParent      = FrameworkElement.GetFrameworkParent(d);
                InheritanceBehavior inheritanceBehavior2 = InheritanceBehavior.Default;
                if (frameworkParent != null)
                {
                    FrameworkObject frameworkObject = new FrameworkObject(frameworkParent, true);
                    inheritanceBehavior2 = frameworkObject.InheritanceBehavior;
                }
                if (!TreeWalkHelper.SkipNext(inheritanceBehavior) && !TreeWalkHelper.SkipNow(inheritanceBehavior2))
                {
                    d.SynchronizeInheritanceParent(frameworkParent);
                }
                if (oldEntry.BaseValueSourceInternal == BaseValueSourceInternal.Unknown)
                {
                    oldEntry = EffectiveValueEntry.CreateDefaultValueEntry(property, metadata.GetDefaultValue(d, property));
                }
            }
            else
            {
                oldEntry = d.GetValueEntry(entryIndex, property, metadata, RequestFlags.RawEntry);
            }
            if (BaseValueSourceInternal.Inherited >= oldEntry.BaseValueSourceInternal)
            {
                if (visitedViaVisualTree && FrameworkElement.DType.IsInstanceOfType(d))
                {
                    DependencyObject parent = LogicalTreeHelper.GetParent(d);
                    if (parent != null)
                    {
                        DependencyObject parent2 = VisualTreeHelper.GetParent(d);
                        if (parent2 != null && parent2 != parent)
                        {
                            return(false);
                        }
                    }
                }
                return((d.UpdateEffectiveValue(entryIndex, property, metadata, oldEntry, ref newEntry, false, false, OperationType.Inherit) & (UpdateResult)5) == UpdateResult.ValueChanged);
            }
            if (flag2)
            {
                newEntry = new EffectiveValueEntry(property, FullValueSource.IsCoerced);
                return((d.UpdateEffectiveValue(d.LookupEntry(property.GlobalIndex), property, metadata, oldEntry, ref newEntry, false, false, OperationType.Inherit) & (UpdateResult)5) == UpdateResult.ValueChanged);
            }
            return(false);
        }