Open datepicker calendar without showing edittextbox in xamarin.forms

I am using the DatePicker control in my application. I have a button and I want to open a popup in which I want to show the DatePicker calendar. But at present, when I open the popup, the edittexbox window edittexbox displayed with the current date, and when I edittexbox on the text box, the calendar opens. But I do not want to edit texbox. I just want to show the calendar when the user clicks on the button.
Does anyone know how I can do this?

+7
source share
4 answers

Hide the DatePicker control by setting IsVisible=false . You can then program it programmatically by calling the Focus() method from another place in your code.

+4
source

Check this:

  DatePicker datePicker = new DatePicker { Format = "D", VerticalOptions = LayoutOptions.CenterAndExpand, IsVisible =false, IsEnabled = false }; Button button = new Button { Text = "Date", VerticalOptions = LayoutOptions.CenterAndExpand }; button.Clicked += (object sender, EventArgs e) => { IsEnabled = true; datePicker.Focus(); button.Text = datePicker.Date.ToString(); }; 

See https://developer.xamarin.com/api/type/Xamarin.Forms.DatePicker/

+1
source

A slightly improved response to Jason's answer. Setting IsVisible in DatePicker to false and then setting it to Focus() works, however, you may find that when you click Cancel, the focus remains on DatePicker. If the DatePicker already has focus, it does not display the date picker again. Here is the code that will always work no matter how the user interacts with the dialog:

  DatePickerTapRecogniser.Tapped += (object sender, EventArgs e) => { Device.BeginInvokeOnMainThread (() => { if (DatePickerComponent.IsFocused) { DatePickerComponent.Unfocus (); } DatePickerComponent.Focus (); }); }; 
+1
source

For your information, the solution proposed by Jason above and refined by Daniel does not work with UWP. This was mentioned elsewhere, therefore not surprisingly.

-1
source

All Articles