Пример #1
0
        /// <summary>
        /// Gets the action associated with the specified Button.
        /// </summary>
        /// <param name="button">The Button to lookup.</param>
        /// <returns>The action associated with the Button; null if there is none.</returns>
        public static TriggerAction GetAction(ButtonBase button)
        {
            TriggerCollection triggers = (TriggerCollection)button.GetValue(TriggersProperty);

            if (triggers != null)
            {
                foreach (Trigger trigger in triggers)
                {
                    ClickTrigger clickTrigger = trigger as ClickTrigger;
                    if (clickTrigger != null)
                    {
                        return(clickTrigger.Action);
                    }
                }
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Sets the action associated with the specified Button.
        /// </summary>
        /// <param name="button">The Button to associate the action with.</param>
        /// <param name="action">The action to associate with the button.</param>
        public static void SetAction(ButtonBase button, TriggerAction action)
        {
            if (action == null)
            {
                return;
            }

            TriggerCollection triggers = GetTriggers(button);

            foreach (Trigger trigger in triggers)
            {
                ClickTrigger clickTrigger = trigger as ClickTrigger;
                clickTrigger.Action = action;
            }

            ClickTrigger newTrigger = new ClickTrigger();

            newTrigger.Action = action;

            triggers.Add(newTrigger);
        }