summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-04-19 07:01:58 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-04-19 07:01:58 (GMT)
commita98f3fb2aae3c5b6a3fa5140e51f51ec67843a49 (patch)
tree654fa47cbd3cc889061466939630dcd5133cc837 /Xamarin.Forms.Platform.WinRT
parent89a50d4bc1f4aaf83d5f92a28c2a7a96282cc0d3 (diff)
downloadxamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.zip
xamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.tar.gz
xamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.tar.bz2
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')
-rw-r--r--Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs24
-rw-r--r--Xamarin.Forms.Platform.WinRT/FormsTimePicker.cs1
-rw-r--r--Xamarin.Forms.Platform.WinRT/PickerRenderer.cs21
-rw-r--r--Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs28
4 files changed, 71 insertions, 3 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs
index 23f134f..88df5cb 100644
--- a/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.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 DatePickerRenderer : ViewRenderer<DatePicker, FormsDatePicker>, IWrapperAware
{
+ Brush _defaultBrush;
+
public void NotifyWrapped()
{
if (Control != null)
@@ -26,6 +30,7 @@ namespace Xamarin.Forms.Platform.WinRT
{
Control.ForceInvalidate -= PickerOnForceInvalidate;
Control.DateChanged -= OnControlDateChanged;
+ Control.Loaded -= ControlOnLoaded;
}
base.Dispose(disposing);
@@ -38,8 +43,9 @@ namespace Xamarin.Forms.Platform.WinRT
if (Control == null)
{
var picker = new FormsDatePicker();
- picker.DateChanged += OnControlDateChanged;
SetNativeControl(picker);
+ Control.Loaded += ControlOnLoaded;
+ Control.DateChanged += OnControlDateChanged;
}
UpdateMinimumDate();
@@ -50,6 +56,14 @@ namespace Xamarin.Forms.Platform.WinRT
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)
{
base.OnElementPropertyChanged(sender, e);
@@ -60,6 +74,8 @@ namespace Xamarin.Forms.Platform.WinRT
UpdateMaximumDate();
else if (e.PropertyName == DatePicker.MinimumDateProperty.PropertyName)
UpdateMinimumDate();
+ else if (e.PropertyName == DatePicker.TextColorProperty.PropertyName)
+ UpdateTextColor();
}
void OnControlDateChanged(object sender, DatePickerValueChangedEventArgs e)
@@ -93,5 +109,11 @@ namespace Xamarin.Forms.Platform.WinRT
DateTime mindate = Element.MinimumDate;
Control.MinYear = new DateTimeOffset(mindate);
}
+
+ void UpdateTextColor()
+ {
+ Color color = Element.TextColor;
+ Control.Foreground = color.IsDefault ? (_defaultBrush ?? color.ToBrush()) : color.ToBrush();
+ }
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.WinRT/FormsTimePicker.cs b/Xamarin.Forms.Platform.WinRT/FormsTimePicker.cs
index 976c56f..c135a58 100644
--- a/Xamarin.Forms.Platform.WinRT/FormsTimePicker.cs
+++ b/Xamarin.Forms.Platform.WinRT/FormsTimePicker.cs
@@ -2,6 +2,7 @@ using System;
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Media;
#if WINDOWS_UWP
diff --git a/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs
index a7fcbb4..e37b79a 100644
--- a/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs
+++ b/Xamarin.Forms.Platform.WinRT/PickerRenderer.cs
@@ -2,7 +2,9 @@
using System.ComponentModel;
using System.Threading.Tasks;
using Windows.UI.Core;
+using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Media;
#if WINDOWS_UWP
@@ -15,6 +17,7 @@ namespace Xamarin.Forms.Platform.WinRT
public class PickerRenderer : ViewRenderer<Picker, FormsComboBox>
{
bool _isAnimating;
+ Brush _defaultBrush;
protected override void Dispose(bool disposing)
{
@@ -27,6 +30,7 @@ namespace Xamarin.Forms.Platform.WinRT
Control.DropDownOpened -= OnDropDownOpenStateChanged;
Control.DropDownClosed -= OnDropDownOpenStateChanged;
Control.OpenAnimationCompleted -= ControlOnOpenAnimationCompleted;
+ Control.Loaded -= ControlOnLoaded;
}
}
@@ -45,6 +49,7 @@ namespace Xamarin.Forms.Platform.WinRT
Control.DropDownClosed += OnDropDownOpenStateChanged;
Control.OpenAnimationCompleted += ControlOnOpenAnimationCompleted;
Control.ClosedAnimationStarted += ControlOnClosedAnimationStarted;
+ Control.Loaded += ControlOnLoaded;
}
Control.ItemsSource = Element.Items;
@@ -64,6 +69,16 @@ namespace Xamarin.Forms.Platform.WinRT
UpdateSelectedIndex();
else if (e.PropertyName == Picker.TitleProperty.PropertyName)
UpdateTitle();
+ else if (e.PropertyName == Picker.TextColorProperty.PropertyName)
+ UpdateTextColor();
+ }
+
+ 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();
}
void ControlOnClosedAnimationStarted(object sender, EventArgs eventArgs)
@@ -139,6 +154,12 @@ namespace Xamarin.Forms.Platform.WinRT
Control.SelectedIndex = Element.SelectedIndex;
}
+ void UpdateTextColor()
+ {
+ Color color = Element.TextColor;
+ Control.Foreground = color.IsDefault ? (_defaultBrush ?? color.ToBrush()) : color.ToBrush();
+ }
+
void UpdateTitle()
{
Control.Header = Element.Title;
diff --git a/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/TimePickerRenderer.cs
index 3aa5fdc..8c878b2 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