/// <summary>Locks this style and all factories and triggers so they cannot be changed.</summary>
 // Token: 0x060008DB RID: 2267 RVA: 0x0001CA5C File Offset: 0x0001AC5C
 public void Seal()
 {
     base.VerifyAccess();
     if (this._sealed)
     {
         return;
     }
     if (this._targetType == null)
     {
         throw new InvalidOperationException(SR.Get("NullPropertyIllegal", new object[]
         {
             "TargetType"
         }));
     }
     if (this._basedOn != null && Style.DefaultTargetType != this._basedOn.TargetType && !this._basedOn.TargetType.IsAssignableFrom(this._targetType))
     {
         throw new InvalidOperationException(SR.Get("MustBaseOnStyleOfABaseType", new object[]
         {
             this._targetType.Name
         }));
     }
     if (this._setters != null)
     {
         this._setters.Seal();
     }
     if (this._visualTriggers != null)
     {
         this._visualTriggers.Seal();
     }
     this.CheckForCircularBasedOnReferences();
     if (this._basedOn != null)
     {
         this._basedOn.Seal();
     }
     if (this._resources != null)
     {
         this._resources.IsReadOnly = true;
     }
     this.ProcessSetters(this);
     StyleHelper.AddEventDependent(0, this.EventHandlersStore, ref this.EventDependents);
     this.ProcessSelfStyles(this);
     this.ProcessVisualTriggers(this);
     StyleHelper.SortResourceDependents(ref this.ResourceDependents);
     this._sealed = true;
     base.DetachFromDispatcher();
 }
Beispiel #2
0
        /// <summary>
        /// This Style and all factories/triggers are now immutable
        /// </summary>
        public void Seal()
        {
            // Verify Context Access
            VerifyAccess();

            // 99% case - Style is already sealed.
            if (_sealed)
            {
                return;
            }

            // Most parameter checking is done as "upstream" as possible, but some
            //  can't be checked until Style is sealed.
            if (_targetType == null)
            {
                throw new InvalidOperationException(SR.Get(SRID.NullPropertyIllegal, "TargetType"));
            }

            if (_basedOn != null)
            {
                if (DefaultTargetType != _basedOn.TargetType &&
                    !_basedOn.TargetType.IsAssignableFrom(_targetType))
                {
                    throw new InvalidOperationException(SR.Get(SRID.MustBaseOnStyleOfABaseType, _targetType.Name));
                }
            }

            // Seal setters
            if (_setters != null)
            {
                _setters.Seal();
            }

            // Seal triggers
            if (_visualTriggers != null)
            {
                _visualTriggers.Seal();
            }

            // Will throw InvalidOperationException if we find a loop of
            //  BasedOn references.  (A.BasedOn = B, B.BasedOn = C, C.BasedOn = A)
            CheckForCircularBasedOnReferences();

            // Seal BasedOn Style chain
            if (_basedOn != null)
            {
                _basedOn.Seal();
            }

            // Seal the ResourceDictionary
            if (_resources != null)
            {
                _resources.IsReadOnly = true;
            }

            //
            // Build shared tables
            //

            // Process all Setters set on the selfStyle. This stores all the property
            // setters on the current styles into PropertyValues list, so it can be used
            // by ProcessSelfStyle in the next step. The EventSetters for the current
            // and all the basedOn styles are merged into the EventHandlersStore on the
            // current style.
            ProcessSetters(this);

            // Add an entry in the EventDependents list for
            // the TargetType's EventHandlersStore. Notice
            // that the childIndex is 0.
            StyleHelper.AddEventDependent(0, this.EventHandlersStore, ref EventDependents);

            // Process all PropertyValues (all are "Self") in the Style
            // chain (base added first)
            ProcessSelfStyles(this);

            // Process all TriggerBase PropertyValues ("Self" triggers
            // and child triggers) in the Style chain last (highest priority)
            ProcessVisualTriggers(this);

            // Sort the ResourceDependents, to help avoid duplicate invalidations
            StyleHelper.SortResourceDependents(ref ResourceDependents);

            // All done, seal self and call it a day.
            _sealed = true;

            // Remove thread affinity so it can be accessed across threads
            DetachFromDispatcher();
        }