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.ComponentModel;
using System.Diagnostics;


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

    // Example 18-8. Obtaining a PropertyDescriptor from TypeDescriptor

    public partial class Window1 : System.Windows.Window
    {

        public Window1()
        {
            InitializeComponent();
            // myButton refers to a <Button> in the XAML (not shown)
            PropertyDescriptor buttonIsPressedProp =
                TypeDescriptor.GetProperties(myButton)["IsPressed"];

            buttonIsPressedProp.AddValueChanged(myButton, OnButtonIsPressedChanged);
        }

        public void AlternativeGetProp()
        {
            // Example 18-9. Obtaining a PropertyDescriptor from a DependencyProperty

            PropertyDescriptor buttonIsPressedProp =
                DependencyPropertyDescriptor.FromProperty(Button.IsPressedProperty,
                                                          typeof(Button));

            // End of Example 18-9

            Debug.WriteLine(buttonIsPressedProp);
        }

        void OnButtonIsPressedChanged(object sender, EventArgs e)
        {
            this.Background = myButton.IsPressed ? Brushes.Red : Brushes.Blue;
        }

    }

    // End of Example 18-8.
}