using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;

namespace DependencyPropertyExample
{
    /// <summary>
    /// Interaction logic for HandleEvent.xaml
    /// </summary>

    public partial class HandleEvent : System.Windows.Window
    {

        public HandleEvent()
        {
            InitializeComponent();


            // Example 18-12. Attached event handler

            RoutedEventHandler handler = MyAlarmHandlerMethod;
            myButton.AddHandler(ClockControl.AlarmEvent, handler);

            // End of Example 18-12.

            myButton.Click += new RoutedEventHandler(myButton_Click);
        }

        void myButton_Click(object sender, RoutedEventArgs e)
        {
            // Example 18-13. Raising an attached event

            RoutedEventArgs re = new RoutedEventArgs(ClockControl.AlarmEvent);
            myButton.RaiseEvent(re);
        
            // End of Example 18-13.
        }

        private void MyAlarmHandlerMethod(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Alarm event raised");
        }

    }
}