Ejemplo n.º 1
0
        /// <summary>
        /// Returns the trigger collection for a particular control.
        /// </summary>
        public static TriggerCollection GetTriggers(Control control)
        {
            TriggerCollection collection;

            if (!instance.triggerLookup.TryGetValue(control, out collection))
            {
                collection = new TriggerCollection(control);
                instance.triggerLookup[control] = collection;
                control.Unloaded += OnControlUnloaded;
            }

            return(collection);
        }
        /// <summary>
        /// Called when the control property changes. Make sure we set the control property
        /// for all the triggers.
        /// </summary>
        private static void OnControlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            TriggerCollection collection = d as TriggerCollection;
            Control           newControl = e.NewValue as Control;

            if (collection != null && newControl != null)
            {
                List <Trigger> triggers = collection.Triggers;
                if (triggers != null)
                {
                    foreach (var trigger in triggers)
                    {
                        trigger.SetValue(Trigger.ControlProperty, newControl);
                    }
                }
            }
        }