using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace NumberFlickerLibrary
{
    public partial class NumberFlicker : UserControl, INotifyPropertyChanged
    {
        public static readonly DependencyProperty NumberValueProperty = DependencyProperty.Register("NumberValue", typeof(int), typeof(FrameworkElement), new PropertyMetadata(0));

        public NumberFlicker()
        {
            // Required to initialize variables
            InitializeComponent();
            this.DataContext = this;
        }

        public int NumberValue
        {
            get 
            { 
                return (int) GetValue(NumberValueProperty);
            }
            set
            {
                if (value == 10)
                {
                    value = 0;
                }
                if (value == -1)
                {
                    value = 9;
                }
                SetValue(NumberValueProperty, value);
                NotifyPropertyChanged("NumberValue");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

        private void upBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NumberValue++;
        }

        private void downBorder_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            NumberValue--;
        }
    }
}