diff options
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs b/Xamarin.Forms.Platform.WinRT/DatePickerRenderer.cs index 23f134f2..88df5cbc 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 |