Exemplo n.º 1
0
        private void ProcessVisualTriggers(Style style)
        {
            // Walk down to bottom of based-on chain
            if (style == null)
            {
                return;
            }

            ProcessVisualTriggers(style._basedOn);

            if (style._visualTriggers != null)
            {
                // Merge in "self" and child TriggerBase PropertyValues while walking
                // back up the tree. "Based-on" style rules are always added first
                // (lower priority)
                int triggerCount = style._visualTriggers.Count;
                for (int i = 0; i < triggerCount; i++)
                {
                    TriggerBase trigger = style._visualTriggers[i];

                    // Set things up to handle Setter values
                    for (int j = 0; j < trigger.PropertyValues.Count; j++)
                    {
                        PropertyValue propertyValue = trigger.PropertyValues[j];

                        // Check for trigger rules that act on container
                        if (propertyValue.ChildName != StyleHelper.SelfName)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.StyleTriggersCannotTargetTheTemplate));
                        }

                        TriggerCondition[] conditions = propertyValue.Conditions;
                        for (int k = 0; k < conditions.Length; k++)
                        {
                            if (conditions[k].SourceName != StyleHelper.SelfName)
                            {
                                throw new InvalidOperationException(SR.Get(SRID.TriggerOnStyleNotAllowedToHaveSource, conditions[k].SourceName));
                            }
                        }

                        // Track properties on the container that are being driven by
                        // the Style so that they can be invalidated during style changes
                        StyleHelper.AddContainerDependent(propertyValue.Property, true /*fromVisualTrigger*/, ref this.ContainerDependents);

                        StyleHelper.UpdateTables(ref propertyValue, ref ChildRecordFromChildIndex,
                                                 ref TriggerSourceRecordFromChildIndex, ref ResourceDependents, ref _dataTriggerRecordFromBinding,
                                                 null /*_childIndexFromChildID*/, ref _hasInstanceValues);
                    }

                    // Set things up to handle TriggerActions
                    if (trigger.HasEnterActions || trigger.HasExitActions)
                    {
                        if (trigger is Trigger)
                        {
                            StyleHelper.AddPropertyTriggerWithAction(trigger, ((Trigger)trigger).Property, ref this.PropertyTriggersWithActions);
                        }
                        else if (trigger is MultiTrigger)
                        {
                            MultiTrigger multiTrigger = (MultiTrigger)trigger;
                            for (int k = 0; k < multiTrigger.Conditions.Count; k++)
                            {
                                Condition triggerCondition = multiTrigger.Conditions[k];

                                StyleHelper.AddPropertyTriggerWithAction(trigger, triggerCondition.Property, ref this.PropertyTriggersWithActions);
                            }
                        }
                        else if (trigger is DataTrigger)
                        {
                            StyleHelper.AddDataTriggerWithAction(trigger, ((DataTrigger)trigger).Binding, ref this.DataTriggersWithActions);
                        }
                        else if (trigger is MultiDataTrigger)
                        {
                            MultiDataTrigger multiDataTrigger = (MultiDataTrigger)trigger;
                            for (int k = 0; k < multiDataTrigger.Conditions.Count; k++)
                            {
                                Condition dataCondition = multiDataTrigger.Conditions[k];

                                StyleHelper.AddDataTriggerWithAction(trigger, dataCondition.Binding, ref this.DataTriggersWithActions);
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException(SR.Get(SRID.UnsupportedTriggerInStyle, trigger.GetType().Name));
                        }
                    }

                    // Set things up to handle EventTrigger
                    EventTrigger eventTrigger = trigger as EventTrigger;
                    if (eventTrigger != null)
                    {
                        if (eventTrigger.SourceName != null && eventTrigger.SourceName.Length > 0)
                        {
                            throw new InvalidOperationException(SR.Get(SRID.EventTriggerOnStyleNotAllowedToHaveTarget, eventTrigger.SourceName));
                        }

                        StyleHelper.ProcessEventTrigger(eventTrigger,
                                                        null /*_childIndexFromChildID*/,
                                                        ref _triggerActions,
                                                        ref EventDependents,
                                                        null /*_templateFactoryRoot*/,
                                                        null,
                                                        ref _eventHandlersStore,
                                                        ref _hasLoadedChangeHandler);
                    }
                }
            }
        }
Exemplo n.º 2
0
 // Token: 0x060008DF RID: 2271 RVA: 0x0001CD9C File Offset: 0x0001AF9C
 private void ProcessVisualTriggers(Style style)
 {
     if (style == null)
     {
         return;
     }
     this.ProcessVisualTriggers(style._basedOn);
     if (style._visualTriggers != null)
     {
         int count = style._visualTriggers.Count;
         for (int i = 0; i < count; i++)
         {
             TriggerBase triggerBase = style._visualTriggers[i];
             for (int j = 0; j < triggerBase.PropertyValues.Count; j++)
             {
                 PropertyValue propertyValue = triggerBase.PropertyValues[j];
                 if (propertyValue.ChildName != "~Self")
                 {
                     throw new InvalidOperationException(SR.Get("StyleTriggersCannotTargetTheTemplate"));
                 }
                 TriggerCondition[] conditions = propertyValue.Conditions;
                 for (int k = 0; k < conditions.Length; k++)
                 {
                     if (conditions[k].SourceName != "~Self")
                     {
                         throw new InvalidOperationException(SR.Get("TriggerOnStyleNotAllowedToHaveSource", new object[]
                         {
                             conditions[k].SourceName
                         }));
                     }
                 }
                 StyleHelper.AddContainerDependent(propertyValue.Property, true, ref this.ContainerDependents);
                 StyleHelper.UpdateTables(ref propertyValue, ref this.ChildRecordFromChildIndex, ref this.TriggerSourceRecordFromChildIndex, ref this.ResourceDependents, ref this._dataTriggerRecordFromBinding, null, ref this._hasInstanceValues);
             }
             if (triggerBase.HasEnterActions || triggerBase.HasExitActions)
             {
                 if (triggerBase is Trigger)
                 {
                     StyleHelper.AddPropertyTriggerWithAction(triggerBase, ((Trigger)triggerBase).Property, ref this.PropertyTriggersWithActions);
                 }
                 else if (triggerBase is MultiTrigger)
                 {
                     MultiTrigger multiTrigger = (MultiTrigger)triggerBase;
                     for (int l = 0; l < multiTrigger.Conditions.Count; l++)
                     {
                         Condition condition = multiTrigger.Conditions[l];
                         StyleHelper.AddPropertyTriggerWithAction(triggerBase, condition.Property, ref this.PropertyTriggersWithActions);
                     }
                 }
                 else if (triggerBase is DataTrigger)
                 {
                     StyleHelper.AddDataTriggerWithAction(triggerBase, ((DataTrigger)triggerBase).Binding, ref this.DataTriggersWithActions);
                 }
                 else
                 {
                     if (!(triggerBase is MultiDataTrigger))
                     {
                         throw new InvalidOperationException(SR.Get("UnsupportedTriggerInStyle", new object[]
                         {
                             triggerBase.GetType().Name
                         }));
                     }
                     MultiDataTrigger multiDataTrigger = (MultiDataTrigger)triggerBase;
                     for (int m = 0; m < multiDataTrigger.Conditions.Count; m++)
                     {
                         Condition condition2 = multiDataTrigger.Conditions[m];
                         StyleHelper.AddDataTriggerWithAction(triggerBase, condition2.Binding, ref this.DataTriggersWithActions);
                     }
                 }
             }
             EventTrigger eventTrigger = triggerBase as EventTrigger;
             if (eventTrigger != null)
             {
                 if (eventTrigger.SourceName != null && eventTrigger.SourceName.Length > 0)
                 {
                     throw new InvalidOperationException(SR.Get("EventTriggerOnStyleNotAllowedToHaveTarget", new object[]
                     {
                         eventTrigger.SourceName
                     }));
                 }
                 StyleHelper.ProcessEventTrigger(eventTrigger, null, ref this._triggerActions, ref this.EventDependents, null, null, ref this._eventHandlersStore, ref this._hasLoadedChangeHandler);
             }
         }
     }
 }