Xamarin.forms: Datepicker is not opened when we call Datepicker.Focus() in UWP

Created on 14 Oct 2019  路  9Comments  路  Source: xamarin/Xamarin.Forms

Description

Datepicker is not opened when we call Datepicker.Focus() in UWP. I have tried to open the date picker dialog on a button click by calling Datepicket.Focust() method. Note: This is working as expected in Android and iOS.

Steps to Reproduce

  1. Run the attached sample.
  2. Click the button "Button"

Expected Behavior

Datepicker dialog should be opened.

Actual Behavior

Datepicker dialog is not opened

Basic Information

  • Version with issue: 4.2.0.709249
  • Last known good version:
  • IDE: VS 2019
  • Platform Target Frameworks:

    • UWP: 177 63

  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices: Desktop
    DatePickerBlankApp.zip
2 in-progress UWP bug

Most helpful comment

I've got an idea on how to address this, working up something now and will post a draft PR for the DatePicker only to get some feedback. Hopefully yet today.

All 9 comments

Confirmed that this is happening. As discussed in #5159, ultimately we want to move away from doing this with focus, but for the time being that is the way to go.

Also, don't forget to check the regular Picker and TimePicker

Hi @jfversluis , Can this issue be addressed in the next pre release atleast for UWP?

@Balasubramanian93, I wish I could say yes, but the truth is that at this time I'm no sure when work on this will be done and when it will be included. Whenever the status is updated you will see it here.

I've got an idea on how to address this, working up something now and will post a draft PR for the DatePicker only to get some feedback. Hopefully yet today.

Let us know how it goes @bmacombe!

Ran into some complications...still working on it. UWP handles these flyouts different then I was expecting based on wpf and silver light. I totally agree having a show method in xf vs on focus would be great!

@jfversluis Quick preview of what I'm thinking.

In the Renderer override OnElementFocusChangeRequested, since this will only be called when Focus() is called on the picker. This then ignores all the focus events from the native uwp control. Which will keep the flyout from opening on things like tabbing through controls, etc. So it will only display on a call to the XF Focus method. Pretty much like if the Show/Open was implemented.

I wanted to avoid the behavior change discussions on this bugzilla issue I found.

https://xamarin.github.io/bugzilla-archives/52/52266/bug.html

```c#
internal override void OnElementFocusChangeRequested(object sender, VisualElement.FocusRequestArgs args)
{
base.OnElementFocusChangeRequested(sender, args);

if (Control.ContextFlyout == null)
{
    var flyout = new DatePickerFlyout();
    flyout.Placement = FlyoutPlacementMode.Bottom;
    Control.ContextFlyout = flyout;
}
Control.ContextFlyout.ShowAt(Control);

}
```

What I have left to figure out is how to make the manual flyout match the same appearance as the flyout when you click on the control. The default opens on top of the control, centered vertically and with the same width.

image

Right now I've only figured out how to set the placement, which all the options don't match the default appearance Now that I have the basic behavior sorted out, I'll start digging into matching the visual appearance.

image

Of course the above method, doesn't actually update the original datepicker value. I'm sure I could bind it...I'm really struggling to find a way to activate the UWP DatePicker Click handling.

@jfversluis I've opened a draft PR for review my approach to this issue, a review at your convenience
would be greatly appreciated.

Was this page helpful?
0 / 5 - 0 ratings