summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8
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.WP8
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.WP8')
-rw-r--r--Xamarin.Forms.Platform.WP8/DatePickerRenderer.cs24
-rw-r--r--Xamarin.Forms.Platform.WP8/PickerRenderer.cs41
-rw-r--r--Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs22
3 files changed, 77 insertions, 10 deletions
diff --git a/Xamarin.Forms.Platform.WP8/DatePickerRenderer.cs b/Xamarin.Forms.Platform.WP8/DatePickerRenderer.cs
index 9553171b..5685310d 100644
--- a/Xamarin.Forms.Platform.WP8/DatePickerRenderer.cs
+++ b/Xamarin.Forms.Platform.WP8/DatePickerRenderer.cs
@@ -1,17 +1,28 @@
´╗┐using System;
using System.ComponentModel;
using System.Reflection;
+using System.Windows.Media;
using Microsoft.Phone.Controls;
namespace Xamarin.Forms.Platform.WinPhone
{
public class DatePickerRenderer : ViewRenderer<DatePicker, Microsoft.Phone.Controls.DatePicker>
{
+ Brush _defaultBrush;
+
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
var datePicker = new Microsoft.Phone.Controls.DatePicker { Value = Element.Date };
+
+ datePicker.Loaded += (sender, args) => {
+ // The defaults from the control template won't be available
+ // right away; we have to wait until after the template has been applied
+ _defaultBrush = datePicker.Foreground;
+ UpdateTextColor();
+ };
+
datePicker.ValueChanged += DatePickerOnValueChanged;
SetNativeControl(datePicker);
@@ -20,11 +31,14 @@ namespace Xamarin.Forms.Platform.WinPhone
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
- if (e.PropertyName == "Date")
+ base.OnElementPropertyChanged(sender, e);
+
+ if (e.PropertyName == DatePicker.DateProperty.PropertyName)
Control.Value = Element.Date;
else if (e.PropertyName == DatePicker.FormatProperty.PropertyName)
UpdateFormatString();
- base.OnElementPropertyChanged(sender, e);
+ else if (e.PropertyName == DatePicker.TextColorProperty.PropertyName)
+ UpdateTextColor();
}
internal override void OnModelFocusChangeRequested(object sender, VisualElement.FocusRequestArgs args)
@@ -55,5 +69,11 @@ namespace Xamarin.Forms.Platform.WinPhone
{
Control.ValueStringFormat = "{0:" + Element.Format + "}";
}
+
+ 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.WP8/PickerRenderer.cs b/Xamarin.Forms.Platform.WP8/PickerRenderer.cs
index f9cd2d81..d52f7314 100644
--- a/Xamarin.Forms.Platform.WP8/PickerRenderer.cs
+++ b/Xamarin.Forms.Platform.WP8/PickerRenderer.cs
@@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
+using System.Windows.Media;
using Microsoft.Phone.Controls;
namespace Xamarin.Forms.Platform.WinPhone
@@ -11,8 +12,8 @@ namespace Xamarin.Forms.Platform.WinPhone
public class PickerRenderer : ViewRenderer<Picker, FrameworkElement>
{
bool _isChanging;
-
FormsListPicker _listPicker;
+ Brush _defaultBrush;
protected override void OnElementChanged(ElementChangedEventArgs<Picker> e)
{
@@ -34,6 +35,12 @@ namespace Xamarin.Forms.Platform.WinPhone
_listPicker.Items.Add(new ItemViewModel(" ") { MaxHeight = 0 });
_listPicker.ListPickerModeChanged += ListPickerModeChanged;
+ _listPicker.Loaded += (sender, args) => {
+ // The defaults from the control template won't be available
+ // right away; we have to wait until after the template has been applied
+ _defaultBrush = _listPicker.Foreground;
+ UpdateTextColor();
+ };
var grid = new System.Windows.Controls.Grid { Children = { _listPicker }, MaxWidth = Device.Info.PixelScreenSize.Width };
SetNativeControl(grid);
@@ -45,20 +52,29 @@ namespace Xamarin.Forms.Platform.WinPhone
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
+
if (e.PropertyName == Picker.TitleProperty.PropertyName)
+ {
_listPicker.FullModeHeader = Element.Title;
-
- if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName)
+ }
+ else if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName)
+ {
UpdateIsEnabled();
-
- if (e.PropertyName == Picker.SelectedIndexProperty.PropertyName)
+ UpdateTextColor();
+ }
+ else if (e.PropertyName == Picker.SelectedIndexProperty.PropertyName)
{
if (Element.SelectedIndex >= 0 && Element.SelectedIndex < Element.Items.Count)
_listPicker.SelectedIndex = Element.SelectedIndex + 1;
}
-
- if (e.PropertyName == View.HorizontalOptionsProperty.PropertyName)
+ else if (e.PropertyName == View.HorizontalOptionsProperty.PropertyName)
+ {
UpdateAlignment();
+ }
+ else if (e.PropertyName == Picker.TextColorProperty.PropertyName)
+ {
+ UpdateTextColor();
+ }
}
protected override void OnGotFocus(object sender, RoutedEventArgs args)
@@ -198,6 +214,17 @@ namespace Xamarin.Forms.Platform.WinPhone
_listPicker.SelectedIndex = Element.SelectedIndex + 1;
}
+ void UpdateTextColor()
+ {
+ if (!_listPicker.IsEnabled)
+ {
+ return;
+ }
+
+ Color color = Element.TextColor;
+ _listPicker.Foreground = color.IsDefault ? (_defaultBrush ?? color.ToBrush()) : color.ToBrush();
+ }
+
class ItemViewModel : INotifyPropertyChanged
{
string _data;
diff --git a/Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs b/Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs
index 70841d7a..542bddfc 100644
--- a/Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs
+++ b/Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs
@@ -1,17 +1,29 @@
´╗┐using System;
using System.ComponentModel;
using System.Reflection;
+using System.Windows.Media;
using Microsoft.Phone.Controls;
namespace Xamarin.Forms.Platform.WinPhone
{
public class TimePickerRenderer : ViewRenderer<TimePicker, Microsoft.Phone.Controls.TimePicker>
{
+ Brush _defaultBrush;
+
protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
{
base.OnElementChanged(e);
var timePicker = new Microsoft.Phone.Controls.TimePicker { Value = DateTime.Today.Add(Element.Time) };
+
+ timePicker.Loaded += (sender, args) =>
+ {
+ // The defaults from the control template won't be available
+ // right away; we have to wait until after the template has been applied
+ _defaultBrush = timePicker.Foreground;
+ UpdateTextColor();
+ };
+
timePicker.ValueChanged += TimePickerOnValueChanged;
SetNativeControl(timePicker);
@@ -22,10 +34,12 @@ namespace Xamarin.Forms.Platform.WinPhone
{
base.OnElementPropertyChanged(sender, e);
- if (e.PropertyName == "Time")
+ if (e.PropertyName == TimePicker.TimeProperty.PropertyName)
Control.Value = DateTime.Today.Add(Element.Time);
else if (e.PropertyName == TimePicker.FormatProperty.PropertyName)
UpdateFormatString();
+ else if (e.PropertyName == TimePicker.TextColorProperty.PropertyName)
+ UpdateTextColor();
}
internal override void OnModelFocusChangeRequested(object sender, VisualElement.FocusRequestArgs args)
@@ -56,5 +70,11 @@ namespace Xamarin.Forms.Platform.WinPhone
{
Control.ValueStringFormat = "{0:" + Element.Format + "}";
}
+
+ void UpdateTextColor()
+ {
+ Color color = Element.TextColor;
+ Control.Foreground = color.IsDefault ? (_defaultBrush ?? color.ToBrush()) : color.ToBrush();
+ }
}
} \ No newline at end of file