//  ===========================================================================
        //  These methods are invoked when a Property is being
        //  invalidated via a Style/Template
        //  ===========================================================================

        #region InvalidateMethods

        //
        //  This method
        //  1. Is invoked when the StyleProperty is invalidated on a FrameworkElement or
        //     FrameworkContentElement or a sub-class thereof.
        //
        internal static void DoStyleInvalidations(
            FrameworkElement fe,
            FrameworkContentElement fce,
            Style oldStyle,
            Style newStyle)
        {
            Debug.Assert(fe != null || fce != null);

            if (oldStyle != newStyle)
            {
                //
                // Style is changing
                //

                DependencyObject container = (fe != null) ? (DependencyObject)fe : (DependencyObject)fce;

                // If the style wants to watch for the Loaded and/or Unloaded events, set the
                // flag that says we want to receive it.  Otherwise, if it was set in the old style, clear it.
                StyleHelper.UpdateLoadedFlag( container, oldStyle, newStyle );

                // Set up any per-instance state relating to the new Style
                // We do this here instead of OnStyleInvalidated because
                //  this needs to happen for the *first* Style.
                StyleHelper.UpdateInstanceData(
                    StyleHelper.StyleDataField,
                    fe, fce,
                    oldStyle, newStyle,
                    null /* oldFrameworkTemplate */, null /* newFrameworkTemplate */,
                    (InternalFlags)0);

                // If this new style has resource references (either for the container
                // or for children in the visual tree), then, mark it so that it will
                // not be ignored during resource change invalidations
                if ((newStyle != null) && (newStyle.HasResourceReferences))
                {
                    if (fe != null)
                    {
                        fe.HasResourceReference = true;
                    }
                    else
                    {
                        fce.HasResourceReference = true;
                    }
                }

                FrugalStructList<ContainerDependent> oldContainerDependents =
                    oldStyle != null ? oldStyle.ContainerDependents : StyleHelper.EmptyContainerDependents;

                FrugalStructList<ContainerDependent> newContainerDependents =
                    newStyle != null ? newStyle.ContainerDependents : StyleHelper.EmptyContainerDependents;

                // Propagate invalidation for Style dependents
                FrugalStructList<ContainerDependent> exclusionContainerDependents =
                    new FrugalStructList<ContainerDependent>();
                StyleHelper.InvalidateContainerDependents(container,
                    ref exclusionContainerDependents,
                    ref oldContainerDependents,
                    ref newContainerDependents);

                // Propagate invalidation for resource references that may be
                // picking stuff from the style's ResourceDictionary
                DoStyleResourcesInvalidations(container, fe, fce, oldStyle, newStyle);

                // Notify Style has changed
                // CALLBACK
                if (fe != null)
                {
                    fe.OnStyleChanged(oldStyle, newStyle);
                }
                else
                {
                    fce.OnStyleChanged(oldStyle, newStyle);
                }
            }
        }