﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace CloudCompanionMockUp
{
    /// <summary>
    /// Interaction logic for IconButtonLeft.xaml
    /// </summary>
    public partial class IconButtonLeft : UserControl
    {
        public IconButtonLeft()
        {
            InitializeComponent();
        }

        #region LabelText Dependency Property

        public String LabelText
        {
            get
            {
                return (String)GetValue(LabelTextProperty);
            }
            set
            {
                try
                {
                    if (this.Dispatcher.CheckAccess())
                    {
                        SetValue(LabelTextProperty, value);
                    }
                    else
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Send, (SendOrPostCallback)delegate
                        {
                            SetValue(LabelTextProperty, value);
                        }, null);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private static FrameworkPropertyMetadata LabelTextMetaData = new FrameworkPropertyMetadata("Submit"
            , FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal
            , new PropertyChangedCallback(LabelText_PropertyChanged)
            , new CoerceValueCallback(LabelText_CoerceValue)
            , false
            , System.Windows.Data.UpdateSourceTrigger.PropertyChanged);

        public static readonly DependencyProperty LabelTextProperty =
            DependencyProperty.Register("LabelText", typeof(String), typeof(IconButtonLeft), LabelTextMetaData, new ValidateValueCallback(LabelText_Validate));

        private static void LabelText_PropertyChanged(DependencyObject dobj, DependencyPropertyChangedEventArgs e)
        {
            //To be called whenever the DP is changed.
            //MessageBox.Show(string.Format("Property changed is fired : OldValue {0} NewValue : {1}", e.OldValue, e.NewValue));
        }

        private static object LabelText_CoerceValue(DependencyObject dobj, object Value)
        {
            //called whenever dependency LabelText value is reevaluated. The return value is the
            //latest value set to the dependency LabelText
            //MessageBox.Show(string.Format("CoerceValue is fired : Value {0}", Value));
            return Value;
        }

        private static bool LabelText_Validate(object Value)
        {
            //Custom validation block which takes in the value of DP
            //Returns true / false based on success / failure of the validation
            //MessageBox.Show(string.Format("DataValidation is Fired : Value {0}", Value));
            return true;
        }

        #endregion LabelText Dependency Property


        #region IconBrush Dependency Property

        public Canvas IconBrush
        {
            get
            {
                return (Canvas)GetValue(IconBrushProperty);
            }
            set
            {
                try
                {
                    if (Dispatcher.CheckAccess())
                    {
                        SetValue(IconBrushProperty, value);
                    }
                    else
                    {
                        Dispatcher.BeginInvoke(DispatcherPriority.Send, (SendOrPostCallback)delegate
                        {
                            SetValue(IconBrushProperty, value);
                        }, null);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }

        private static FrameworkPropertyMetadata _IconBrushMetaData = new FrameworkPropertyMetadata(null
            , FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal
            , new PropertyChangedCallback(IconBrush_PropertyChanged)
            , new CoerceValueCallback(IconBrush_CoerceValue)
            , false
            , UpdateSourceTrigger.PropertyChanged);

        public static readonly DependencyProperty IconBrushProperty =
            DependencyProperty.Register("IconBrush", typeof(Canvas), typeof(IconButtonLeft), _IconBrushMetaData, new ValidateValueCallback(IconBrush_Validate));

        private static void IconBrush_PropertyChanged(DependencyObject dobj, DependencyPropertyChangedEventArgs e)
        {
            //To be called whenever the DP is changed.
            //MessageBox.Show(string.Format("Property changed is fired : OldValue {0} NewValue : {1}", e.OldValue, e.NewValue));
        }

        private static object IconBrush_CoerceValue(DependencyObject dobj, object value)
        {
            //called whenever dependency IconBrush value is reevaluated. The return value is the
            //latest value set to the dependency IconBrush
            //MessageBox.Show(string.Format("CoerceValue is fired : Value {0}", Value));
            return value;
        }

        private static bool IconBrush_Validate(object value)
        {
            //Custom validation block which takes in the value of DP
            //Returns true / false based on success / failure of the validation
            //MessageBox.Show(string.Format("DataValidation is Fired : Value {0}", Value));
            return true;
        }

        #endregion IconBrush Dependency Property
    }
}
