using CPF; 
using CPF.Controls; 

namespace OVCS.ClientLinux
{
    [CPF.Design.DesignerLoadStyle("res://OVCS.ClientLinux/Stylesheet1.css")]//用于设计的时候加载样式

    ////自定义的输入框控件
    public class ElTextBox : TextBox
    {
        public int marginTop = 0;
        public int textLeft = 8;
        public int marginTopPla = 4;
        public int Size = 12;
        private string foreGround = "192,196,204";

        public TextBoxView textBoxView
        {
            get
            {
                return (TextBoxView)this.TextBoxView;
                //return null;
            }
        }

        public string ForeGround
        {
            get { return foreGround; }
            set { foreGround = value; }
        }

        protected override void InitializeComponent()
        {
            this.Children.Add(new Border
            {
                BorderStroke = "0",
                Margin = "0",
                Child = new ScrollViewer
                {
                    MarginTop = marginTop,
                    Width = "100%",
                    Height = "100%",
                    Name = "scrollViewer",
                    PresenterFor = this,
                    Content = TextBoxView,
                    Bindings = {
                        { nameof(ScrollViewer.HorizontalScrollBarVisibility), nameof(TextBox.HScrollBarVisibility), this },
                        { nameof(ScrollViewer.VerticalScrollBarVisibility), nameof(TextBox.VScrollBarVisibility), this }
                    }
                }
            });
            Children.Add(new TextBlock
            {
                Name = "placeholder",
                FontSize = Size,
                MarginLeft = textLeft,
                MarginTop = marginTopPla,
                IsHitTestVisible = false,
                Foreground = foreGround,
                Bindings =
                {
                    {nameof(TextBlock.Text),nameof(Placeholder),this },
                    {nameof(TextBlock.Visibility),nameof(Text),this,BindingMode.OneWay,(string pl)=>string.IsNullOrEmpty(pl)?Visibility.Visible:Visibility.Collapsed },
                }
            });
        }

        public string Placeholder
        {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }
    }
}
