summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-04-19 01:01:58 -0600
committerJason Smith <jason.smith@xamarin.com>2016-04-19 00:01:58 -0700
commita98f3fb2aae3c5b6a3fa5140e51f51ec67843a49 (patch)
tree654fa47cbd3cc889061466939630dcd5133cc837 /Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs
parent89a50d4bc1f4aaf83d5f92a28c2a7a96282cc0d3 (diff)
downloadxamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.tar.gz
xamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.tar.bz2
xamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.zip
Add TextColor Property to Picker, TimePicker, DatePicker (#84)
* Add TextColor property to TimePicker Add TextColor page to TimePicker gallery Add TimePicker color toggling to color toggle test page Split color toggle tests up among tabs * Implement TimePicker.TextColor in iOS * Implement TimePicker.TextColor for WinRT tablet * Add IsEnabled=false tests to DefaultColorToggleTest Button and TimePicker Consolidate ColorStates array Fix IsEnabled changing color bug on iOS * Implement TimePicker.TextColor for WP8 * Add TextColor property to DatePicker Add DatePicker section to DefaultColorToggleTest Impement DatePicker.TextColor for WP8 * Implement DatePicker.TextColor for WinRT/UWP/Windows Phone 8.1 * Implement DatePicker.TextColor for iOS * Add TextColor to DatePicker Gallery Page * Implement DatePicker.TextColor for Android * Add Picker Gallery page for TextColor Implement Picker.TextColor on Android Consolidate TextColor management for Button, Picker, DatePicker, TimePicker Implement * Add untracked TextColorSwitcher Implement Picker.TextColor in iOS * Implement Picker.TextColor in WinRT/UWP/Windows Phone 8.1 Remove Pioker Loaded handlers in Dispose * Implement Picker.TextColor in WP8 * Removed unused field Update ignored warnings * Update docs * Use nameof() for BindableProperties * Cleanup * Fix custom renderer crashes for classes using TextColorSwitcher * Correct property name references * Fix typo and 'if' formatting * Add missing else
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs28
1 files changed, 26 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs
index 3aa5fdca..8c878b29 100644
--- a/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs
@@ -1,6 +1,8 @@
using System;
using System.ComponentModel;
+using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Media;
#if WINDOWS_UWP
@@ -12,6 +14,8 @@ namespace Xamarin.Forms.Platform.WinRT
{
public class TimePickerRenderer : ViewRenderer<TimePicker, FormsTimePicker>, IWrapperAware
{
+ Brush _defaultBrush;
+
public void NotifyWrapped()
{
if (Control != null)
@@ -26,6 +30,7 @@ namespace Xamarin.Forms.Platform.WinRT
{
Control.ForceInvalidate -= PickerOnForceInvalidate;
Control.TimeChanged -= OnControlTimeChanged;
+ Control.Loaded -= ControlOnLoaded;
}
base.Dispose(disposing);
@@ -33,19 +38,29 @@ namespace Xamarin.Forms.Platform.WinRT
protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
{
+ base.OnElementChanged(e);
+
if (e.NewElement != null)
{
if (Control == null)
{
var picker = new FormsTimePicker();
- picker.TimeChanged += OnControlTimeChanged;
SetNativeControl(picker);
+
+ Control.TimeChanged += OnControlTimeChanged;
+ Control.Loaded += ControlOnLoaded;
}
UpdateTime();
}
+ }
- base.OnElementChanged(e);
+ void ControlOnLoaded(object sender, RoutedEventArgs routedEventArgs)
+ {
+ // The defaults from the control template won't be available
+ // right away; we have to wait until after the template has been applied
+ _defaultBrush = Control.Foreground;
+ UpdateTextColor();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
@@ -54,6 +69,9 @@ namespace Xamarin.Forms.Platform.WinRT
if (e.PropertyName == TimePicker.TimeProperty.PropertyName)
UpdateTime();
+
+ if (e.PropertyName == TimePicker.TextColorProperty.PropertyName)
+ UpdateTextColor();
}
void OnControlTimeChanged(object sender, TimePickerValueChangedEventArgs e)
@@ -71,5 +89,11 @@ namespace Xamarin.Forms.Platform.WinRT
{
Control.Time = Element.Time;
}
+
+ void UpdateTextColor()
+ {
+ Color color = Element.TextColor;
+ Control.Foreground = color.IsDefault ? (_defaultBrush ?? color.ToBrush()) : color.ToBrush();
+ }
}
} \ No newline at end of file