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

namespace DependencyPropertyExample
{
    // Example 18-3. Registering attached properties

    public class ElementWithAttachedProp : Panel
    {

        public static readonly DependencyProperty IsSkewedProperty;

        static ElementWithAttachedProp()
        {
            // Example 18-6. Handling property changes (part 1)
            PropertyChangedCallback isSkewedChanged =
                new PropertyChangedCallback(OnIsSkewedChanged);
            PropertyMetadata isSkewedMetadata =
                new PropertyMetadata(false, isSkewedChanged);

            // End of Example 18-6. (part 1)

            IsSkewedProperty = DependencyProperty.RegisterAttached("IsSkewed",
                typeof(bool), typeof(ElementWithAttachedProp), isSkewedMetadata);
        }

        public static bool GetIsSkewed(DependencyObject target)
        {
            return (bool) target.GetValue(IsSkewedProperty);
        }

        public static void SetIsSkewed(DependencyObject target, bool value)
        {
            target.SetValue(IsSkewedProperty, value);
        }


        // Example 18-6. Handling property changes (part 2)

        static void OnIsSkewedChanged(DependencyObject target,
                              DependencyPropertyChangedEventArgs e)
        {
            Debug.WriteLine("IsSkewed just changed: " + e.NewValue);
        }

        // End of Example 18-6. (part 2)

    }

    // End of Example 18-3
}
