using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Diagnostics;

namespace TesterBinder
{
    class TestingBindObject : Entry
    {

        public TestingBindObject()
        {
            HorizontalOptions = LayoutOptions.FillAndExpand;
            BindingContext = this;
        }

        public static BindableProperty BlahStringProperty =
            BindableProperty.Create(
                nameof(BlahString),
                typeof(String),
                typeof(TestingBindObject),
                null,
                BindingMode.TwoWay,
                propertyChanged: BlahSourceChanged
        );

        public String BlahString
        {
            get
            {
                return (string)GetValue(BlahStringProperty);
            }
            set
            {
                SetValue(BlahStringProperty, value);
                OnPropertyChanged(nameof(BlahString));
            }
        }

        private static void BlahSourceChanged(BindableObject bindable, object oldValue, object newValue)
        {
            var customObject = bindable as TestingBindObject;
            var customResult = newValue as String;

            if (customObject != null)
            {
                Debug.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1");
                customObject.BlahString = customResult;
            }
        }

    }
}
