public MaterialDatePicker()
        {
            InitializeComponent();
            EntryField.BindingContext    = this;
            BottomBorder.BackgroundColor = DefaultColor;
            EntryField.Focused          += (s, a) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    EntryField.Unfocus();
                    Picker.Focus();
                });
            };
            Picker.Focused += async(s, a) =>
            {
                HiddenBottomBorder.BackgroundColor = AccentColor;
                HiddenLabel.TextColor = AccentColor;
                HiddenLabel.IsVisible = true;
                if (string.IsNullOrEmpty(EntryField.Text))
                {
                    // animate both at the same time
                    await Task.WhenAll(
                        HiddenBottomBorder.LayoutTo(new Rectangle(BottomBorder.X, BottomBorder.Y, BottomBorder.Width, BottomBorder.Height), 200),
                        HiddenLabel.FadeTo(1, 60),
                        HiddenLabel.TranslateTo(HiddenLabel.TranslationX, EntryField.Y - EntryField.Height + 4, 200, Easing.BounceIn)
                        );

                    EntryField.Placeholder = null;
                }
                else
                {
                    await HiddenBottomBorder.LayoutTo(new Rectangle(BottomBorder.X, BottomBorder.Y, BottomBorder.Width, BottomBorder.Height), 200);
                }
            };
            Picker.Unfocused += async(s, a) =>
            {
                if (IsValid)
                {
                    HiddenLabel.TextColor = DefaultColor;
                }
                Picker_DateSelected(s, new DateChangedEventArgs(Picker.Date, Picker.Date));
                if (string.IsNullOrEmpty(EntryField.Text))
                {
                    // animate both at the same time
                    await Task.WhenAll(
                        HiddenBottomBorder.LayoutTo(new Rectangle(BottomBorder.X, BottomBorder.Y, 0, BottomBorder.Height), 200),
                        HiddenLabel.FadeTo(0, 180),
                        HiddenLabel.TranslateTo(HiddenLabel.TranslationX, EntryField.Y, 200, Easing.BounceIn)
                        );

                    EntryField.Placeholder = Placeholder;
                }
                else
                {
                    await HiddenBottomBorder.LayoutTo(new Rectangle(BottomBorder.X, BottomBorder.Y, 0, BottomBorder.Height), 200);
                }
            };

            Picker.DateSelected += Picker_DateSelected;
        }
示例#2
0
        public MaterialTimePicker()
        {
            InitializeComponent();
            EntryField.BindingContext = this;
            EntryField.Focused       += (s, a) =>
            {
                EntryField.Unfocus();
                Picker.Focus();
            };
            Picker.Focused += async(s, a) =>
            {
                HiddenBottomBorder.BackgroundColor = AccentColor;
                HiddenLabel.TextColor = AccentColor;
                HiddenLabel.IsVisible = true;
                if (string.IsNullOrEmpty(EntryField.Text))
                {
                    // animate both at the same time
                    await Task.WhenAll(
                        HiddenBottomBorder.LayoutTo(new Rectangle(BottomBorder.X, BottomBorder.Y, BottomBorder.Width, BottomBorder.Height), 200),
                        HiddenLabel.FadeTo(1, 60),
                        HiddenLabel.TranslateTo(HiddenLabel.TranslationX, EntryField.Y - EntryField.Height + 4, 200, Easing.BounceIn)
                        );

                    EntryField.Placeholder = null;
                }
                else
                {
                    await HiddenBottomBorder.LayoutTo(new Rectangle(BottomBorder.X, BottomBorder.Y, BottomBorder.Width, BottomBorder.Height), 200);
                }
            };
            Picker.Unfocused += async(s, a) =>
            {
                HiddenLabel.TextColor = Color.Gray;
                if (Time == null)
                {
                    // animate both at the same time
                    await Task.WhenAll(
                        HiddenBottomBorder.LayoutTo(new Rectangle(BottomBorder.X, BottomBorder.Y, 0, BottomBorder.Height), 200),
                        HiddenLabel.FadeTo(0, 180),
                        HiddenLabel.TranslateTo(HiddenLabel.TranslationX, EntryField.Y, 200, Easing.BounceIn)
                        );

                    EntryField.Placeholder = Placeholder;
                }
                else
                {
                    await HiddenBottomBorder.LayoutTo(new Rectangle(BottomBorder.X, BottomBorder.Y, 0, BottomBorder.Height), 200);
                }
            };

            Picker.PropertyChanged += Picker_PropertyChanged;;
        }
        public MaterialDatePicker()
        {
            InitializeComponent();
            EntryField.BindingContext    = this;
            Picker.BindingContext        = this;
            BottomBorder.BackgroundColor = DefaultColor;
            EntryField.Focused          += (s, a) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    EntryField.Unfocus();
                    Picker.Focus();
                });
            };
            Picker.Focused += async(s, a) =>
            {
                await CalculateLayoutFocused();
            };
            Picker.Unfocused += async(s, a) =>
            {
                EntryUnfocused?.Invoke(this, a);
                await CalculateLayoutUnfocused();
            };

            Picker.PropertyChanged += async(sender, args) =>
            {
                if (args.PropertyName == nameof(Picker.NullableDate))
                {
                    CustomDateFormat = CustomDateFormat ?? _defaultDateFormat;
                    var datepicker = (BorderlessDatePicker)sender;
                    EntryField.Text = datepicker.NullableDate.Value.ToString(CustomDateFormat, CultureInfo.CurrentCulture);
                    this.Date       = datepicker.NullableDate;
                    await CalculateLayoutUnfocused();
                }
            };

            //UpdateValidation();
        }