diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2017-02-03 11:13:53 -0700 |
---|---|---|
committer | Samantha Houts <samantha@teamredwall.com> | 2017-02-03 10:13:53 -0800 |
commit | 5af224a1e7679a618149ecac2aa0d8b7eb6cb629 (patch) | |
tree | 9ff345804719d5a513fc6b6b2e92b68f48119fe0 /Xamarin.Forms.Platform.WinRT | |
parent | a67b176051196dfee3a7c1a6b88e257f84136fff (diff) | |
download | xamarin-forms-5af224a1e7679a618149ecac2aa0d8b7eb6cb629.tar.gz xamarin-forms-5af224a1e7679a618149ecac2aa0d8b7eb6cb629.tar.bz2 xamarin-forms-5af224a1e7679a618149ecac2aa0d8b7eb6cb629.zip |
Fix disappearing ListView text when changing color settings on Windows (#731)
* repro
* Checkpoint
* Checkpoint
* Remove now-unnecessary hacks for Time- and DatePicker
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT')
7 files changed, 9 insertions, 229 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs index 646d7d33..677563e3 100644 --- a/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs @@ -13,23 +13,14 @@ namespace Xamarin.Forms.Platform.UWP namespace Xamarin.Forms.Platform.WinRT #endif { - public class DatePickerRenderer : ViewRenderer<DatePicker, FormsDatePicker>, IWrapperAware + public class DatePickerRenderer : ViewRenderer<DatePicker, Windows.UI.Xaml.Controls.DatePicker> { Brush _defaultBrush; - public void NotifyWrapped() - { - if (Control != null) - { - Control.ForceInvalidate += PickerOnForceInvalidate; - } - } - protected override void Dispose(bool disposing) { if (disposing && Control != null) { - Control.ForceInvalidate -= PickerOnForceInvalidate; Control.DateChanged -= OnControlDateChanged; Control.Loaded -= ControlOnLoaded; } @@ -43,7 +34,7 @@ namespace Xamarin.Forms.Platform.WinRT { if (Control == null) { - var picker = new FormsDatePicker(); + var picker = new Windows.UI.Xaml.Controls.DatePicker(); SetNativeControl(picker); Control.Loaded += ControlOnLoaded; Control.DateChanged += OnControlDateChanged; @@ -89,11 +80,6 @@ namespace Xamarin.Forms.Platform.WinRT ((IVisualElementController)Element).InvalidateMeasure(InvalidationTrigger.SizeRequestChanged); } - void PickerOnForceInvalidate(object sender, EventArgs eventArgs) - { - ((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.SizeRequestChanged); - } - void UpdateDate(DateTime date) { Control.Date = date; diff --git a/Xamarin.Forms.Platform.WinRT/FormsDatePicker.cs b/Xamarin.Forms.Platform.WinRT/FormsDatePicker.cs deleted file mode 100644 index 44127423..00000000 --- a/Xamarin.Forms.Platform.WinRT/FormsDatePicker.cs +++ /dev/null @@ -1,76 +0,0 @@ -using System; -using Windows.UI.Core; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; - -#if WINDOWS_UWP - -namespace Xamarin.Forms.Platform.UWP -#else - -namespace Xamarin.Forms.Platform.WinRT -#endif -{ - public class FormsDatePicker : Windows.UI.Xaml.Controls.DatePicker - { - public FormsDatePicker() - { - if (Device.Idiom == TargetIdiom.Desktop || Device.Idiom == TargetIdiom.Tablet) - { - Loaded += (sender, args) => { Window.Current.Activated += WindowOnActivated; }; - Unloaded += (sender, args) => { Window.Current.Activated -= WindowOnActivated; }; - } - } - - public event EventHandler<EventArgs> ForceInvalidate; - - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if (Device.Idiom == TargetIdiom.Desktop || Device.Idiom == TargetIdiom.Tablet) - { - // Look for the combo boxes which make up a DatePicker on Windows 8.1 - // So we can hook into their closed events and invalidate them if necessary - - var dayPicker = GetTemplateChild("DayPicker") as ComboBox; - if (dayPicker != null) - { - dayPicker.DropDownClosed += PickerOnDropDownClosed; - } - - var monthPicker = GetTemplateChild("MonthPicker") as ComboBox; - if (monthPicker != null) - { - monthPicker.DropDownClosed += PickerOnDropDownClosed; - } - - var yearPicker = GetTemplateChild("YearPicker") as ComboBox; - if (yearPicker != null) - { - yearPicker.DropDownClosed += PickerOnDropDownClosed; - } - } - } - - void PickerOnDropDownClosed(object sender, object o) - { - // If the DatePicker is in a TableView or ListView and the user - // opens one of the dropdowns but does not actually change the value, - // when the dropdown closes, the selected value will go blank - // To fix this, we have to invalidate the control - // This only applies to Windows 8.1 - ForceInvalidate?.Invoke(this, EventArgs.Empty); - } - - void WindowOnActivated(object sender, WindowActivatedEventArgs windowActivatedEventArgs) - { - // If the DatePicker is in a TableView or ListView, when the application loses and then regains focus - // the TextBlock/ComboBox controls (UWP and 8.1, respectively) which display its selected value - // will go blank. - // To fix this, we have to signal the renderer to invalidate if - // Window.Activated occurs. - ForceInvalidate?.Invoke(this, EventArgs.Empty); - } - } -}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/FormsTimePicker.cs b/Xamarin.Forms.Platform.WinRT/FormsTimePicker.cs deleted file mode 100644 index c135a585..00000000 --- a/Xamarin.Forms.Platform.WinRT/FormsTimePicker.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using Windows.UI.Core; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Media; - -#if WINDOWS_UWP - -namespace Xamarin.Forms.Platform.UWP -#else - -namespace Xamarin.Forms.Platform.WinRT -#endif -{ - public class FormsTimePicker : Windows.UI.Xaml.Controls.TimePicker - { - public FormsTimePicker() - { - if (Device.Idiom == TargetIdiom.Desktop || Device.Idiom == TargetIdiom.Tablet) - { - Loaded += (sender, args) => { Window.Current.Activated += WindowOnActivated; }; - Unloaded += (sender, args) => { Window.Current.Activated -= WindowOnActivated; }; - } - } - - public event EventHandler<EventArgs> ForceInvalidate; - - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if (Device.Idiom == TargetIdiom.Desktop || Device.Idiom == TargetIdiom.Tablet) - { - // Look for the combo boxes which make up a TimePicker on Windows 8.1 - // So we can hook into their closed events and invalidate them if necessary - - var hourPicker = GetTemplateChild("HourPicker") as ComboBox; - if (hourPicker != null) - { - hourPicker.DropDownClosed += PickerOnDropDownClosed; - } - - var minutePicker = GetTemplateChild("MinutePicker") as ComboBox; - if (minutePicker != null) - { - minutePicker.DropDownClosed += PickerOnDropDownClosed; - } - - var periodPicker = GetTemplateChild("PeriodPicker") as ComboBox; - if (periodPicker != null) - { - periodPicker.DropDownClosed += PickerOnDropDownClosed; - } - } - } - - void PickerOnDropDownClosed(object sender, object o) - { - // If the TimePicker is in a TableView or ListView and the user - // opens one of the dropdowns but does not actually change the value, - // when the dropdown closes, the selected value will go blank - // To fix this, we have to invalidate the control - // This only applies to Windows 8.1 - ForceInvalidate?.Invoke(this, EventArgs.Empty); - } - - void WindowOnActivated(object sender, WindowActivatedEventArgs windowActivatedEventArgs) - { - // If the TimePicker is in a TableView or ListView, when the application loses focus - // the TextBlock/ComboBox controls (UWP and 8.1, respectively) which display its selected value - // will go blank. - // To fix this, we have to signal the renderer to invalidate if - // Window.Activated occurs. - ForceInvalidate?.Invoke(this, EventArgs.Empty); - } - } -}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/IWrapperAware.cs b/Xamarin.Forms.Platform.WinRT/IWrapperAware.cs deleted file mode 100644 index aff90133..00000000 --- a/Xamarin.Forms.Platform.WinRT/IWrapperAware.cs +++ /dev/null @@ -1,14 +0,0 @@ - -#if WINDOWS_UWP - -namespace Xamarin.Forms.Platform.UWP -#else - -namespace Xamarin.Forms.Platform.WinRT -#endif -{ - internal interface IWrapperAware - { - void NotifyWrapped(); - } -}
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs index 0095cdc4..59ce8fcd 100644 --- a/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs +++ b/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs @@ -1,5 +1,4 @@ -using System; -using System.ComponentModel; +using System.ComponentModel; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Media; @@ -13,23 +12,14 @@ namespace Xamarin.Forms.Platform.UWP namespace Xamarin.Forms.Platform.WinRT #endif { - public class TimePickerRenderer : ViewRenderer<TimePicker, FormsTimePicker>, IWrapperAware + public class TimePickerRenderer : ViewRenderer<TimePicker, Windows.UI.Xaml.Controls.TimePicker> { Brush _defaultBrush; - public void NotifyWrapped() - { - if (Control != null) - { - Control.ForceInvalidate += PickerOnForceInvalidate; - } - } - protected override void Dispose(bool disposing) { if (disposing && Control != null) { - Control.ForceInvalidate -= PickerOnForceInvalidate; Control.TimeChanged -= OnControlTimeChanged; Control.Loaded -= ControlOnLoaded; } @@ -45,7 +35,7 @@ namespace Xamarin.Forms.Platform.WinRT { if (Control == null) { - var picker = new FormsTimePicker(); + var picker = new Windows.UI.Xaml.Controls.TimePicker(); SetNativeControl(picker); Control.TimeChanged += OnControlTimeChanged; @@ -81,11 +71,6 @@ namespace Xamarin.Forms.Platform.WinRT ((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.SizeRequestChanged); } - void PickerOnForceInvalidate(object sender, EventArgs eventArgs) - { - ((IVisualElementController)Element)?.InvalidateMeasure(InvalidationTrigger.SizeRequestChanged); - } - void UpdateTime() { Control.Time = Element.Time; diff --git a/Xamarin.Forms.Platform.WinRT/ViewToRendererConverter.cs b/Xamarin.Forms.Platform.WinRT/ViewToRendererConverter.cs index 3d5906dc..15124258 100644 --- a/Xamarin.Forms.Platform.WinRT/ViewToRendererConverter.cs +++ b/Xamarin.Forms.Platform.WinRT/ViewToRendererConverter.cs @@ -2,7 +2,6 @@ using Windows.Foundation; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; -using Xamarin.Forms.Internals; #if WINDOWS_UWP @@ -38,11 +37,11 @@ namespace Xamarin.Forms.Platform.WinRT throw new NotSupportedException(); } - class WrapperControl : ContentControl + class WrapperControl : Canvas { readonly View _view; - FrameworkElement FrameworkElement => Content as FrameworkElement; + FrameworkElement FrameworkElement { get; } public WrapperControl(View view) { @@ -52,9 +51,8 @@ namespace Xamarin.Forms.Platform.WinRT IVisualElementRenderer renderer = Platform.CreateRenderer(view); Platform.SetRenderer(view, renderer); - NotifyWrapperAwareDescendants(view, renderer); - - Content = renderer.ContainerElement; + FrameworkElement = renderer.ContainerElement; + Children.Add(renderer.ContainerElement); // make sure we re-measure once the template is applied if (FrameworkElement != null) @@ -100,25 +98,6 @@ namespace Xamarin.Forms.Platform.WinRT return result; } - - void NotifyWrapperAwareDescendants(Element currentView, IVisualElementRenderer currentRenderer) - { - // If any of the child renderers need to handle anything differently because they're in - // a wrapper in a list view, let them know that they're being wrapped - var wrapperAwareRenderer = currentRenderer as IWrapperAware; - wrapperAwareRenderer?.NotifyWrapped(); - - foreach (Element child in ((IElementController)currentView).LogicalChildren) - { - var childView = child as View; - if (childView == null) - { - continue; - } - - NotifyWrapperAwareDescendants(childView, Platform.GetRenderer(childView)); - } - } } } }
\ No newline at end of file diff --git a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj index 766fd728..339e1924 100644 --- a/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj +++ b/Xamarin.Forms.Platform.WinRT/Xamarin.Forms.Platform.WinRT.csproj @@ -80,9 +80,6 @@ <Compile Include="LayoutExtensions.cs" /> <Compile Include="PlatformEffect.cs" /> <Compile Include="FormsComboBox.cs" /> - <Compile Include="IWrapperAware.cs" /> - <Compile Include="FormsDatePicker.cs" /> - <Compile Include="FormsTimePicker.cs" /> <Compile Include="FormsTextBox.cs" /> <Compile Include="ITitleProvider.cs" /> <Compile Include="IToolbarProvider.cs" /> |