/// <summary>
        /// Helper method for EvalTriggers().
        /// </summary>
        /// <param name="type">Type of trigger to search for.</param>
        /// <param name="stateIfTrue">Reference to the visual state variable to update (if the trigger occurs).</param>
        private void ApplyCondition(VisualStateTriggerTypes type, ref TState stateIfTrue)
        {
            foreach (VisualStateTrigger <TState> trigger in Triggers.Where(x => x.Type == type))
            {
                if (trigger != null)
                {
                    Rectangle bounds = (trigger.Bounds != Rectangle.Empty) ? trigger.Bounds : Control.ClientRectangle;

                    bool inRect = bounds.Contains(Control.PointToClient(Cursor.Position));
                    bool other  = true;

                    switch (type)
                    {
                    case VisualStateTriggerTypes.Focused:
                        other  = Control.Focused;
                        inRect = true;
                        break;

                    case VisualStateTriggerTypes.Pushed:
                        other = (Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left;
                        break;
                    }
                    if (other && inRect)
                    {
                        stateIfTrue = trigger.State;
                    }
                }
            }
        }
 /// <summary>
 /// Initialises a new instance of the VisualStateTrigger class.
 /// </summary>
 /// <param name="type">Type of trigger.</param>
 /// <param name="state">Visual state applied when the trigger occurs.</param>
 /// <param name="bounds">Bounds within which the trigger applies.</param>
 public VisualStateTrigger(VisualStateTriggerTypes type, TState state, Rectangle bounds = default(Rectangle), AnchorStyles anchor = AnchorStyles.Top | AnchorStyles.Left)
 {
     Type   = type;
     State  = state;
     Bounds = bounds;
     Anchor = anchor;
 }
 /// <summary>
 /// Short-hand method for adding a state change trigger.
 /// </summary>
 /// <param name="type">Type of trigger.</param>
 /// <param name="state">Visual state applied when the trigger occurs.</param>
 /// <param name="bounds">Bounds within which the trigger applies.</param>
 /// <param name="anchor">How the bounds are anchored to the control.</param>
 public void AddTrigger(VisualStateTriggerTypes type, TState state, Rectangle bounds = default(Rectangle), AnchorStyles anchor = AnchorStyles.Top | AnchorStyles.Left)
 {
     Triggers.Add(new VisualStateTrigger <TState>(type, state, bounds, anchor));
 }