public void OnTimeSet(TimePicker view, int hoursOfDay, int minute) { var time = blankPicker.Time = new TimeSpan(hoursOfDay, minute, 0); Control.Text = new DateTime(time.Ticks).ToString(blankPicker.Format); EController.SetValueFromRenderer(VisualElement.IsFocusedProperty, false); Control.ClearFocus(); HideKeyboard(); blankPicker.SendDoneClicked(); _dialog = null; }
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) => { var timeOfDay = _picker.Date.ToDateTime().TimeOfDay; var time = new TimeSpan(timeOfDay.Hours, timeOfDay.Minutes, 0); blankPicker.Text = Control.Text = new DateTime(time.Ticks).ToString(blankPicker.Format); blankPicker.Time = time; 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; }
public void OnPickerClick(object sender, EventArgs e) { _dialog = new TimePickerDialog(Context, (s, d) => { EController.SetValueFromRenderer(Xamarin.Forms.TimePicker.TimeProperty, new TimeSpan(d.HourOfDay, d.Minute, 0)); EController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); Control.ClearFocus(); _dialog = null; }, this.Element.Time.Hours, this.Element.Time.Minutes, true); _dialog.SetButton(blankPicker.CancelButtonText, (s, el) => { blankPicker.SendCancelClicked(); }); _dialog.SetButton2(blankPicker.DoneButtonText, (k, p) => { this.Control.Text = Element.Time.ToString(Element.Format); blankPicker.SendDoneClicked(); }); _dialog.Show(); }