public void OnPickerClick(object sender, EventArgs e) { Xamarin.Forms.DatePicker model = Element; _dialog = new DatePickerDialog(Context, (o, d) => { model.Date = d.Date; EController.SetValueFromRenderer(VisualElement.IsFocusedProperty, false); Control.ClearFocus(); _dialog = null; }, this.Element.Date.Year, this.Element.Date.Month - 1, this.Element.Date.Day); _dialog.DatePicker.MaxDate = UnixTimestampFromDateTime(Element.MaximumDate); _dialog.DatePicker.MinDate = UnixTimestampFromDateTime(Element.MinimumDate); _dialog.SetButton(blankPicker.DoneButtonText, (k, p) => { this.Control.Text = _dialog.DatePicker.DateTime.ToString(Element.Format); Element.Date = _dialog.DatePicker.DateTime; blankPicker.SendDoneClicked(); }); _dialog.SetButton2(blankPicker.CancelButtonText, (s, el) => { blankPicker.SendCancelClicked(); }); _dialog.Show(); }
public void OnClick(object sender, EventArgs e) { HideKeyboard(); _dialog = new DatePickerDialog(Context, this, blankPicker.Date.Year, blankPicker.Date.Month - 1, blankPicker.Date.Day); _dialog.DatePicker.MaxDate = UnixTimestampFromDateTime(blankPicker.MaximumDate); _dialog.DatePicker.MinDate = UnixTimestampFromDateTime(blankPicker.MinimumDate); _dialog.SetButton(blankPicker.DoneButtonText, (k, p) => { blankPicker.Text = _dialog.DatePicker.DateTime.ToString(blankPicker.Format); blankPicker.Date = _dialog.DatePicker.DateTime; blankPicker.SendDoneClicked(); EController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); Control.ClearFocus(); HideKeyboard(); }); _dialog.SetButton2(blankPicker.CancelButtonText, (s, el) => { blankPicker.SendCancelClicked(); EController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); Control.ClearFocus(); HideKeyboard(); }); _dialog.CancelEvent += _dialog_DismissEvent; _dialog.Show(); }
public void SetInputAccessoryView() { if (string.IsNullOrEmpty(blankPicker.DoneButtonText) && string.IsNullOrEmpty(blankPicker.CancelButtonText)) { Control.InputAccessoryView = null; return; } var toolbar = new UIToolbar { BarStyle = UIBarStyle.Default, Translucent = true }; toolbar.SizeToFit(); var items = new List <UIBarButtonItem>(); if (!string.IsNullOrEmpty(blankPicker.CancelButtonText)) { var cancelButton = new UIBarButtonItem(blankPicker.CancelButtonText, UIBarButtonItemStyle.Done, (s, ev) => { Control.ResignFirstResponder(); }); cancelButton.Clicked += (sender, e) => blankPicker.SendCancelClicked(); items.Add(cancelButton); } var flexible = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); items.Add(flexible); if (!string.IsNullOrEmpty(blankPicker.DoneButtonText)) { var doneButton = new UIBarButtonItem(blankPicker.DoneButtonText, UIBarButtonItemStyle.Done, (s, ev) => { blankPicker.Text = Control.Text = _picker.Date.ToDateTime().Date.ToString(blankPicker.Format); blankPicker.Date = _picker.Date.ToDateTime().Date; if (blankPicker != null) { blankPicker.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); } Control.ResignFirstResponder(); }); doneButton.Clicked += (sender, e) => blankPicker.SendDoneClicked(); items.Add(doneButton); } toolbar.SetItems(items.ToArray(), true); Control.InputAccessoryView = toolbar; Control.InputAccessoryView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight; }
public void SetUIButtons() { if (string.IsNullOrEmpty(blankPicker.DoneButtonText) && string.IsNullOrEmpty(blankPicker.CancelButtonText)) { Control.InputAccessoryView = null; return; } UIToolbar toolbar = new UIToolbar { BarStyle = UIBarStyle.Default, Translucent = true }; toolbar.SizeToFit(); var items = new List <UIBarButtonItem>(); if (!string.IsNullOrEmpty(blankPicker.CancelButtonText)) { UIBarButtonItem cancelButton = new UIBarButtonItem(blankPicker.CancelButtonText, UIBarButtonItemStyle.Done, (s, ev) => { Control.ResignFirstResponder(); }); cancelButton.Clicked += (sender, e) => { blankPicker.SendCancelClicked(); }; items.Add(cancelButton); } UIBarButtonItem flexible = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); items.Add(flexible); if (!string.IsNullOrEmpty(blankPicker.DoneButtonText)) { UIBarButtonItem doneButton = new UIBarButtonItem(blankPicker.DoneButtonText, UIBarButtonItemStyle.Done, (s, ev) => { Control.ResignFirstResponder(); }); doneButton.Clicked += (sender, e) => { blankPicker.SendDoneClicked(); }; items.Add(doneButton); } toolbar.SetItems(items.ToArray(), true); Control.InputAccessoryView = toolbar; }