Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Fixes 7992 Changes UWP DatePicker to show the picker flyout on DatePickerFocus() #8056

Merged
merged 15 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 7992, "Datepicker is not opened when we call Datepicker.Focus() in UWP", PlatformAffected.UWP)]

public class Issue7992 : TestContentPage
{
protected override void Init()
{
var stackLayout = new StackLayout();
Content = stackLayout;

stackLayout.Children.Add(new Label
{
Text = "Label to keep picker from getting initial focus"
});

var datePicker = new DatePicker();
stackLayout.Children.Add(datePicker);

var buttonFocus = new Button
{
Text = "Calls Focus() on the date picker, which should open a date picker flyout."
};
buttonFocus.Clicked += (s, e) =>
{
datePicker.IsVisible = true;
datePicker.Focus();
};
stackLayout.Children.Add(buttonFocus);

var buttonNotVisible = new Button
{
Text = "Makes the picker not visible and calls Focus(), which should open a full screen picker flyout."
};
buttonNotVisible.Clicked += (s, e) =>
{
datePicker.IsVisible = false;
datePicker.Focus();
};
stackLayout.Children.Add(buttonNotVisible);

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue7593.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue7992.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue7792.xaml.cs">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -1758,4 +1759,4 @@
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>
13 changes: 13 additions & 0 deletions Xamarin.Forms.Platform.UAP/DatePickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Windows.UI.Text;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Media;
using Xamarin.Forms.Internals;
Expand Down Expand Up @@ -65,6 +66,18 @@ void ControlOnLoaded(object sender, RoutedEventArgs routedEventArgs)
UpdateTextColor();
}

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

// Show a picker fly out on focus to match iOS and Android behavior
var flyout = new DatePickerFlyout { Placement = FlyoutPlacementMode.Bottom, Date = Control.Date };
flyout.DatePicked += (p, e) => Control.Date = p.Date;
if (!Element.IsVisible)
flyout.Placement = FlyoutPlacementMode.Full;
flyout.ShowAt(Control);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this behave when the picker is set to not visible? See for instance #5159

Copy link
Contributor Author

@bmacombe bmacombe Oct 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick test on when it's not visible, it opens but I'm not sure the positioning is great. Seems like it will open at the root coordinate of the current screen.

image

What I'm thinking to do is if the control isn't visible use the Full placement of the flyout, which will have the picker popup fill the current screen.

image

Thoughts?

I'll also update the issue page to include both a visible and not visible control.

}

void WireUpFormsVsm()
{
if (!Element.UseFormsVsm())
Expand Down