summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 20:02:25 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-03-22 23:13:41 (GMT)
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs b/Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs
new file mode 100644
index 0000000..70841d7
--- /dev/null
+++ b/Xamarin.Forms.Platform.WP8/TimePickerRenderer.cs
@@ -0,0 +1,60 @@
+´╗┐using System;
+using System.ComponentModel;
+using System.Reflection;
+using Microsoft.Phone.Controls;
+
+namespace Xamarin.Forms.Platform.WinPhone
+{
+ public class TimePickerRenderer : ViewRenderer<TimePicker, Microsoft.Phone.Controls.TimePicker>
+ {
+ protected override void OnElementChanged(ElementChangedEventArgs<TimePicker> e)
+ {
+ base.OnElementChanged(e);
+
+ var timePicker = new Microsoft.Phone.Controls.TimePicker { Value = DateTime.Today.Add(Element.Time) };
+ timePicker.ValueChanged += TimePickerOnValueChanged;
+
+ SetNativeControl(timePicker);
+ UpdateFormatString();
+ }
+
+ protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ base.OnElementPropertyChanged(sender, e);
+
+ if (e.PropertyName == "Time")
+ Control.Value = DateTime.Today.Add(Element.Time);
+ else if (e.PropertyName == TimePicker.FormatProperty.PropertyName)
+ UpdateFormatString();
+ }
+
+ internal override void OnModelFocusChangeRequested(object sender, VisualElement.FocusRequestArgs args)
+ {
+ Microsoft.Phone.Controls.TimePicker control = Control;
+ if (control == null)
+ return;
+
+ if (args.Focus)
+ {
+ typeof(DateTimePickerBase).InvokeMember("OpenPickerPage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, Type.DefaultBinder, control, null);
+ args.Result = true;
+ }
+ else
+ {
+ UnfocusControl(control);
+ args.Result = true;
+ }
+ }
+
+ void TimePickerOnValueChanged(object sender, DateTimeValueChangedEventArgs dateTimeValueChangedEventArgs)
+ {
+ if (Control.Value != null)
+ ((IElementController)Element).SetValueFromRenderer(TimePicker.TimeProperty, Control.Value.Value - DateTime.Today);
+ }
+
+ void UpdateFormatString()
+ {
+ Control.ValueStringFormat = "{0:" + Element.Format + "}";
+ }
+ }
+} \ No newline at end of file