void CreateDialog()
        {
            var date = AddDatePicker.GetDate(Element);

            _dialog = new DatePickerDialog(_view.Context, (o, e) => {
                AddDatePicker.SetDate(Element, e.Date);
                _command?.Execute(e.Date);
                _view.ClearFocus();
                _dialog.CancelEvent -= OnCancelButtonClicked;

                _dialog = null;
            }, date.Year, date.Month - 1, date.Day);

            _dialog.SetCanceledOnTouchOutside(true);
        }
 void UpdateCommand()
 {
     _command = AddDatePicker.GetCommand(Element);
 }
Example #3
0
 void UpdateMinDate()
 {
     _picker.MinimumDate = AddDatePicker.GetMinDate(Element).ToNSDate();
 }
Example #4
0
 void UpdateMaxDate()
 {
     _picker.MaximumDate = AddDatePicker.GetMaxDate(Element).ToNSDate();
 }
Example #5
0
        void CreatePicker()
        {
            _entry                 = new NoCaretField();
            _entry.BorderStyle     = UITextBorderStyle.None;
            _entry.BackgroundColor = UIColor.Clear;
            _view.AddSubview(_entry);

            _entry.TranslatesAutoresizingMaskIntoConstraints = false;

            _entry.TopAnchor.ConstraintEqualTo(_view.TopAnchor).Active       = true;
            _entry.LeftAnchor.ConstraintEqualTo(_view.LeftAnchor).Active     = true;
            _entry.BottomAnchor.ConstraintEqualTo(_view.BottomAnchor).Active = true;
            _entry.RightAnchor.ConstraintEqualTo(_view.RightAnchor).Active   = true;
            _entry.WidthAnchor.ConstraintEqualTo(_view.WidthAnchor).Active   = true;
            _entry.HeightAnchor.ConstraintEqualTo(_view.HeightAnchor).Active = true;

            _view.UserInteractionEnabled = true;
            _view.SendSubviewToBack(_entry);

            _picker = new UIDatePicker {
                Mode = UIDatePickerMode.Date, TimeZone = new Foundation.NSTimeZone("UTC")
            };
            if (UIDevice.CurrentDevice.CheckSystemVersion(14, 0))
            {
                _picker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels;
            }

            var todayText = AddDatePicker.GetTodayText(Element);

            var width   = UIScreen.MainScreen.Bounds.Width;
            var toolbar = new UIToolbar(new CGRect(0, 0, (float)width, 44))
            {
                BarStyle = UIBarStyle.Default, Translucent = true
            };
            var cancelButton = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (o, e) => {
                _entry.ResignFirstResponder();
                _picker.Date = _preSelectedDate;
            });

            var spacer     = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
            var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => {
                _entry.ResignFirstResponder();
                DoneDate();
                _command?.Execute(_picker.Date.ToDateTime().Date);
            });

            if (!string.IsNullOrEmpty(todayText))
            {
                var labelButton = new UIBarButtonItem(todayText, UIBarButtonItemStyle.Plain, (sender, e) => {
                    SetToday();
                });
                var fixspacer = new UIBarButtonItem(UIBarButtonSystemItem.FixedSpace)
                {
                    Width = 20
                };
                toolbar.SetItems(new[] { cancelButton, spacer, labelButton, fixspacer, doneButton }, false);
            }
            else
            {
                toolbar.SetItems(new[] { cancelButton, spacer, doneButton }, false);
            }

            _entry.InputView          = _picker;
            _entry.InputAccessoryView = toolbar;
        }