Bug 24610 - Calling a DatePicker's .Focus() won't cause it to display
Summary: Calling a DatePicker's .Focus() won't cause it to display
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-11-18 08:50 UTC by Brad R
Modified: 2017-05-30 15:18 UTC (History)
11 users (show)

Is this bug a regression?: ---
Last known good build:

Sample solution (2.49 MB, application/x-zip-compressed)
2014-11-18 08:50 UTC, Brad R

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Brad R 2014-11-18 08:50:05 UTC
Created attachment 8781 [details]
Sample solution

I'm trying to create a sample of the issue where calling the .Focus() on a Picker will open up several dialogs despite firing once (https://forums.xamarin.com/discussion/26019/picker-shows-5-modals-during-focus).  However, I seem to have run into another issue.  Creating a very basic content page with a DatePicker tied to a cell, and a button, the button's clicked event will not show the DatePicker despite calling its' focus.

The button's clicked event is firing, and it is updating the date properly, but the .Focus() will not cause it to display the actual Picker.  I'm just trying to get past this so that I can create a working example of the original issue I was seeing.

Comment 1 asimk 2014-12-30 07:25:32 UTC
I have checked this issue with the help of sample app attached in bug description and not able to reproduce it. I observed that when I click on datepicker, datepicker is getting open and I am able to update date successfully. When I click on 'Click to open Date Picker", days of datepicker is updated as per written code. It is working fine at our end.

Please refer the screencast: 

Please review the screencast and let us know what additional steps we need to follow to reproductive this issue.

Environment Info:
Microsoft Visual Studio Professional 2012
Version 11.0.61030.00 Update 4
Microsoft .NET Framework
Version 4.5.51641

Xamarin (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS (840a925103a0bf4a856507f13d5eaee3c1579c2f)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 2 Alessandro 2016-01-14 22:36:43 UTC
I have some problems with TimePicker.Focus and DatePicker.Focus (on iOS).
This is a page I use for tests:

	public class PagePickers : ContentPage
		public PagePickers ()

			StackLayout sl = new StackLayout ();
			sl.Padding = new Thickness (0, 20, 0, 0);
			sl.Spacing = 50;
			sl.HorizontalOptions = LayoutOptions.CenterAndExpand;

			TimePicker tp = new TimePicker ();
			//tp.IsVisible = false;

			DatePicker dp = new DatePicker ();
			//dp.IsVisible = false;

			sl.Children.Add (tp);
			sl.Children.Add (dp);

			Label labelTime = new Label ();
			labelTime.Text = "Press to show TimePicker";

			Label labelDate = new Label ();
			labelDate.Text = "Press to show DatePicker";

			TapGestureRecognizer grTime = new TapGestureRecognizer ();
			grTime.Tapped +=  (object sender, EventArgs e) => {
				 tp.Focus(); // = true;

			TapGestureRecognizer grDate = new TapGestureRecognizer ();
			grDate.Tapped +=  (object sender, EventArgs e) => {
				dp.Focus(); // = true;
			labelTime.GestureRecognizers.Add (grTime);
			labelDate.GestureRecognizers.Add (grDate);

			sl.Children.Add (labelTime);
			sl.Children.Add (labelDate);

			Button buttonTime = new Button ();
			buttonTime.Text = "Press to show TimePicker";
			buttonTime.Clicked += (object sender, EventArgs e) => {
			Button buttonDate = new Button ();
			buttonDate.Text = "Press to show DatePicker";
			buttonDate.Clicked += (object sender, EventArgs e) => {


			sl.Children.Add (buttonTime);
			sl.Children.Add (buttonDate);
			Content = sl;

with Button, Focus() works fine, but with Gestures, Pickers are not always displayed.

I am using XF
Comment 3 Jason Smith [MSFT] 2016-03-25 18:30:53 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we no longer believe it affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team
Comment 4 Kerry 2016-06-13 07:50:34 UTC
I'm still seeing this error in the latest version,
Comment 5 Vu 2016-06-23 11:07:45 UTC
I've same issue with latest version Button work well, but TapGestureRecognizer sometime working and most of times not working :(
Comment 6 Guillermo Tinoco 2016-11-16 15:32:40 UTC
try this when you use TapGestureRecognizer

grTime.Tapped +=  (object sender, EventArgs e) => {
  Device.BeginInvokeOnMainThread (() => {
    tp.Focus ();

grDate.Tapped +=  (object sender, EventArgs e) => {
  Device.BeginInvokeOnMainThread (() => {
    dp.Focus ();
Comment 7 tu4756 2017-05-30 15:18:39 UTC
@Guillermo Tinoco, running this on the main thread like that fixed this issue for me. Which is a bit strange considering the tap event should be running on the main thread in the first place.