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

Commit 0faabe0

Browse files
bmacombermarinho
authored andcommitted
Fixes 7992 Changes UWP DatePicker to show the picker flyout on DatePickerFocus() (#8056)
* Setup test page * initial DatePickerRenderer Changes * wip * Open Flyout on OnElementFocusChangeRequested * Update to handle when picker not visible Co-authored-by: Rui Marinho <[email protected]> Fixes #7992
1 parent 9876607 commit 0faabe0

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Xamarin.Forms.CustomAttributes;
2+
using Xamarin.Forms.Internals;
3+
4+
namespace Xamarin.Forms.Controls.Issues
5+
{
6+
[Preserve(AllMembers = true)]
7+
[Issue(IssueTracker.Github, 7992, "Datepicker is not opened when we call Datepicker.Focus() in UWP", PlatformAffected.UWP)]
8+
9+
public class Issue7992 : TestContentPage
10+
{
11+
protected override void Init()
12+
{
13+
var stackLayout = new StackLayout();
14+
Content = stackLayout;
15+
16+
stackLayout.Children.Add(new Label
17+
{
18+
Text = "Label to keep picker from getting initial focus"
19+
});
20+
21+
var datePicker = new DatePicker();
22+
stackLayout.Children.Add(datePicker);
23+
24+
var buttonFocus = new Button
25+
{
26+
Text = "Calls Focus() on the date picker, which should open a date picker flyout."
27+
};
28+
buttonFocus.Clicked += (s, e) =>
29+
{
30+
datePicker.IsVisible = true;
31+
datePicker.Focus();
32+
};
33+
stackLayout.Children.Add(buttonFocus);
34+
35+
var buttonNotVisible = new Button
36+
{
37+
Text = "Makes the picker not visible and calls Focus(), which should open a full screen picker flyout."
38+
};
39+
buttonNotVisible.Clicked += (s, e) =>
40+
{
41+
datePicker.IsVisible = false;
42+
datePicker.Focus();
43+
};
44+
stackLayout.Children.Add(buttonNotVisible);
45+
46+
}
47+
48+
}
49+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<Compile Include="$(MSBuildThisFileDirectory)Issue7593.xaml.cs">
114114
<SubType>Code</SubType>
115115
</Compile>
116+
<Compile Include="$(MSBuildThisFileDirectory)Issue7992.cs" />
116117
<Compile Include="$(MSBuildThisFileDirectory)Issue7792.xaml.cs">
117118
<SubType>Code</SubType>
118119
</Compile>
@@ -1762,4 +1763,4 @@
17621763
<Generator>MSBuild:Compile</Generator>
17631764
</EmbeddedResource>
17641765
</ItemGroup>
1765-
</Project>
1766+
</Project>

Xamarin.Forms.Platform.UAP/DatePickerRenderer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Windows.UI.Text;
55
using Windows.UI.Xaml;
66
using Windows.UI.Xaml.Controls;
7+
using Windows.UI.Xaml.Controls.Primitives;
78
using Windows.UI.Xaml.Documents;
89
using Windows.UI.Xaml.Media;
910
using Xamarin.Forms.Internals;
@@ -65,6 +66,18 @@ void ControlOnLoaded(object sender, RoutedEventArgs routedEventArgs)
6566
UpdateTextColor();
6667
}
6768

69+
internal override void OnElementFocusChangeRequested(object sender, VisualElement.FocusRequestArgs args)
70+
{
71+
base.OnElementFocusChangeRequested(sender, args);
72+
73+
// Show a picker fly out on focus to match iOS and Android behavior
74+
var flyout = new DatePickerFlyout { Placement = FlyoutPlacementMode.Bottom, Date = Control.Date };
75+
flyout.DatePicked += (p, e) => Control.Date = p.Date;
76+
if (!Element.IsVisible)
77+
flyout.Placement = FlyoutPlacementMode.Full;
78+
flyout.ShowAt(Control);
79+
}
80+
6881
void WireUpFormsVsm()
6982
{
7083
if (!Element.UseFormsVsm())

0 commit comments

Comments
 (0)