using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace ButtonCustomDepProp_ChangeNot
{
    class MyButton:Button
    {
        public static readonly DependencyProperty CountProperty = DependencyProperty.Register(
"Count", typeof(int), typeof(MyButton), new FrameworkPropertyMetadata(0, new PropertyChangedCallback(OnCountChanged)));

        public int Count
        {
            get { return (int)GetValue(MyButton.CountProperty); }
            set { SetValue(MyButton.CountProperty, value); }
        }
        
        public static void OnCountChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) {
            MyButton b = o as MyButton;
            if ((int)e.NewValue == 3)
            {
                b.Background = Brushes.Green;
            }

        }

    }
   
}
