using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;

namespace DependencyPropertyExample
{
    // Example 18-11. Defining a custom RoutedEvent

    public class ClockControl : ContentControl
    {

        public static RoutedEvent AlarmEvent;
        public static RoutedEvent PreviewAlarmEvent;

        // Example 18-14. Registering a custom command
        public static RoutedUICommand SnoozeCommand;

        static ClockControl()
        {
            InputGestureCollection boomInputs = new InputGestureCollection();
            boomInputs.Add(new KeyGesture(Key.F,
                                         ModifierKeys.Control | ModifierKeys.Shift));
            SnoozeCommand = new RoutedUICommand("Snooze", "Snooze",
                                         typeof(ClockControl), boomInputs);

            // End of Example 18-14.

            AlarmEvent = EventManager.RegisterRoutedEvent(
                "Alarm", RoutingStrategy.Bubble,
                typeof(RoutedEventHandler), typeof(ClockControl));
            PreviewAlarmEvent = EventManager.RegisterRoutedEvent(
                "PreviewAlarm", RoutingStrategy.Tunnel,
                typeof(RoutedEventHandler), typeof(ClockControl));
        }

        public event RoutedEventHandler Alarm
        {
            add { AddHandler(AlarmEvent, value); }
            remove { RemoveHandler(AlarmEvent, value); }
        }
        public event RoutedEventHandler PreviewAlarm
        {
            add { AddHandler(PreviewAlarmEvent, value); }
            remove { RemoveHandler(PreviewAlarmEvent, value); }
        }

        protected virtual void OnAlarm()
        {
            RoutedEventArgs args = new RoutedEventArgs(PreviewAlarmEvent);
            RaiseEvent(args);
            if (!args.Handled)
            {
                args = new RoutedEventArgs(AlarmEvent);
                RaiseEvent(args);
            }
        }
    }

    // End of Example 18-11.

}
