public bool Contains(SetterBase setter)
    {
      if (setter == null)
      {
        throw new ArgumentNullException("setter");
      }

      return List.Contains(setter);
    }
    public void Add(SetterBase setter)
    {
      if (setter == null)
      {
        throw new ArgumentNullException("setter");
      }

      List.Add(setter);
    }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SetterItem"/> class.
 /// </summary>
 public SetterItem(SetterBase setterBase, FrameworkElement source)
 {
     var setter = setterBase as Setter;
     if (setter != null)
     {
         Property = setter.Property.Name;
         if (setter.Value is DynamicResourceExtension)
         {
             var resourceKey = ((DynamicResourceExtension) setter.Value).ResourceKey;
             Value = ResourceItemFactory.CreateResourceItem(resourceKey, source.Resources, source, ResourceScope.Style);
         }
         else if (setter.Value != null)
         {
             Value = setter.Value;
         }
         else
         {
             Value = "null";
         }
     }
 }
    public void Insert(int index, SetterBase setter)
    {
      if (setter == null)
      {
        throw new ArgumentNullException("setter");
      }

      List.Insert(index, setter);
    }
    public int IndexOf(SetterBase setter)
    {
      if (setter == null)
      {
        throw new ArgumentNullException("setter");
      }

      return List.IndexOf(setter);
    }
    public bool Remove(SetterBase setter)
    {
      if (setter == null)
      {
        throw new ArgumentNullException("setter");
      }

      if (List.Contains(setter) == false)
      {
        return false;
      }

      List.Remove(setter);

      return true;
    }
예제 #7
0
        // Iterates through the setters collection and adds the EventSetter information into
        // an EventHandlersStore for easy and fast retrieval during event routing. Also adds
        // an entry in the EventDependents list for EventhandlersStore holding the TargetType's
        // events.
        private void ProcessSetters(Style style)
        {
            // Walk down to bottom of based-on chain
            if (style == null)
            {
                return;
            }

            style.Setters.Seal(); // Does not mark individual setters as sealed, that's up to the loop below.


            // On-demand create the PropertyValues list, so that we can specify the right size.

            if (PropertyValues.Count == 0)
            {
                PropertyValues = new FrugalStructList <System.Windows.PropertyValue>(style.Setters.Count);
            }

            // Add EventSetters to local EventHandlersStore
            for (int i = 0; i < style.Setters.Count; i++)
            {
                SetterBase setterBase = style.Setters[i];
                Debug.Assert(setterBase != null, "Setter collection must contain non-null instances of SetterBase");

                // Setters are folded into the PropertyValues table only for the current style. The
                // processing of BasedOn Style properties will occur in subsequent call to ProcessSelfStyle
                Setter setter = setterBase as Setter;
                if (setter != null)
                {
                    // Style Setters are not allowed to have a child target name - since there are no child nodes in a Style.
                    if (setter.TargetName != null)
                    {
                        throw new InvalidOperationException(SR.Get(SRID.SetterOnStyleNotAllowedToHaveTarget, setter.TargetName));
                    }

                    if (style == this)
                    {
                        DynamicResourceExtension dynamicResource = setter.ValueInternal as DynamicResourceExtension;
                        if (dynamicResource == null)
                        {
                            UpdatePropertyValueList(setter.Property, PropertyValueType.Set, setter.ValueInternal);
                        }
                        else
                        {
                            UpdatePropertyValueList(setter.Property, PropertyValueType.Resource, dynamicResource.ResourceKey);
                        }
                    }
                }
                else
                {
                    Debug.Assert(setterBase is EventSetter,
                                 "Unsupported SetterBase subclass in style triggers ({0})", setterBase.GetType().ToString());

                    // Add this to the _eventHandlersStore

                    EventSetter eventSetter = (EventSetter)setterBase;
                    if (_eventHandlersStore == null)
                    {
                        _eventHandlersStore = new EventHandlersStore();
                    }
                    _eventHandlersStore.AddRoutedEventHandler(eventSetter.Event, eventSetter.Handler, eventSetter.HandledEventsToo);

                    SetModified(HasEventSetter);

                    // If this event setter watches the loaded/unloaded events, set the optimization
                    // flag.

                    if (eventSetter.Event == FrameworkElement.LoadedEvent || eventSetter.Event == FrameworkElement.UnloadedEvent)
                    {
                        _hasLoadedChangeHandler = true;
                    }
                }
            }

            // Process EventSetters on based on style so they get merged
            // into the EventHandlersStore for the current style.
            ProcessSetters(style._basedOn);
        }