From 933d6809ecc004ed672eef1342dcc73ad97946ca Mon Sep 17 00:00:00 2001 From: BradChase2011 Date: Wed, 31 Jan 2018 13:18:40 -0500 Subject: [PATCH] [UWP] Fixed inconsistency on UWP's DatePicker and the other OS's. (#1183) * [UWP] Fixed inconsistency on UWP's DatePicker and the other OS's. * [UWP] bz60001 Test case. * * [UWP] Fixed inconsistency on UWP's DatePicker and the other OS's. (Build fix) --- .../Bugzilla60001.cs | 34 +++++++++++++++++++ ...rin.Forms.Controls.Issues.Shared.projitems | 1 + .../DatePickerRenderer.cs | 22 +++++++----- 3 files changed, 48 insertions(+), 9 deletions(-) create mode 100644 Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla60001.cs diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla60001.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla60001.cs new file mode 100644 index 000000000..d75a7c096 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla60001.cs @@ -0,0 +1,34 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; +using System; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +// Apply the default category of "Issues" to all of the tests in this assembly +// We use this as a catch-all for tests which haven't been individually categorized +#if UITEST +[assembly: NUnit.Framework.Category("Issues")] +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 60001, "[UWP] Inconsistency with DatePicker ", PlatformAffected.UWP)] + public class Bugzilla60001 : TestContentPage // or TestMasterDetailPage, etc ... + { + protected override void Init() + { + StackLayout layout = new StackLayout() { Orientation = StackOrientation.Vertical }; + DatePicker picker = new DatePicker(); + picker.Date = new DateTime(2017, 10, 7, 0, 0, 0, DateTimeKind.Utc); + Label label = new Label() { Text = "On Droid this will show as 10/7/2017, on UWP it will show as 10/06/2017. Local TimeZone for this test was EDT.", LineBreakMode = LineBreakMode.WordWrap }; + layout.Children.Add(picker); + layout.Children.Add(label); + // Initialize ui here instead of ctor + Content = layout; + } + } +} \ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 9028b6596..c7e9605ba 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -234,6 +234,7 @@ + diff --git a/Xamarin.Forms.Platform.UAP/DatePickerRenderer.cs b/Xamarin.Forms.Platform.UAP/DatePickerRenderer.cs index bb1f965d7..0d1c71883 100644 --- a/Xamarin.Forms.Platform.UAP/DatePickerRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/DatePickerRenderer.cs @@ -98,17 +98,20 @@ namespace Xamarin.Forms.Platform.UWP void OnControlDateChanged(object sender, DatePickerValueChangedEventArgs e) { - Element.Date = e.NewDate.Date; - DateTime currentDate = Element.Date; - if (currentDate != e.NewDate.Date) // Match coerced value - UpdateDate(currentDate); + if (Element == null) + return; - ((IVisualElementController)Element).InvalidateMeasure(InvalidationTrigger.SizeRequestChanged); + if (Element.Date.CompareTo(e.NewDate.Date) != 0) + { + Element.Date = e.NewDate.Date; + ((IVisualElementController)Element).InvalidateMeasure(InvalidationTrigger.SizeRequestChanged); + } } void UpdateDate(DateTime date) { - Control.Date = date; + if (Control != null) + Control.Date = new DateTimeOffset(new DateTime(date.Ticks, DateTimeKind.Unspecified)); } void UpdateFlowDirection() @@ -151,8 +154,8 @@ namespace Xamarin.Forms.Platform.UWP void UpdateMaximumDate() { - DateTime maxdate = Element.MaximumDate; - Control.MaxYear = new DateTimeOffset(maxdate); + if (Element != null && Control != null) + Control.MaxYear = new DateTimeOffset(new DateTime(Element.MaximumDate.Ticks, DateTimeKind.Unspecified)); } void UpdateMinimumDate() @@ -161,7 +164,8 @@ namespace Xamarin.Forms.Platform.UWP try { - Control.MinYear = new DateTimeOffset(mindate); + if (Element != null && Control != null) + Control.MinYear = new DateTimeOffset(new DateTime(Element.MinimumDate.Ticks, DateTimeKind.Unspecified)); } catch (ArgumentOutOfRangeException) {