using System; using ELayout = ElmSharp.Layout; namespace Xamarin.Forms.Platform.Tizen { public class DatePickerRenderer : ViewRenderer { //TODO need to add internationalization support const string DialogTitle = "Choose Date"; Native.Entry _realControl = null; public DatePickerRenderer() { RegisterPropertyHandler(DatePicker.DateProperty, UpdateDate); RegisterPropertyHandler(DatePicker.FormatProperty, UpdateDate); RegisterPropertyHandler(DatePicker.TextColorProperty, UpdateTextColor); } protected override void OnElementChanged(ElementChangedEventArgs e) { if (Control == null) { var layout = new ELayout(Forms.Context.MainWindow); layout.SetTheme("layout", "editfield", "singleline"); _realControl = new Native.Entry(layout) { IsSingleLine = true, HorizontalTextAlignment = Native.TextAlignment.Center, }; _realControl.AllowFocus(false); layout.SetPartContent("elm.swallow.content", _realControl); SetNativeControl(layout); } if (e.OldElement != null) { _realControl.Clicked -= ClickedHandler; } if (e.NewElement != null) { _realControl.Clicked += ClickedHandler; } base.OnElementChanged(e); } void ClickedHandler(object sender, EventArgs e) { Native.DateTimePickerDialog dialog = new Native.DateTimePickerDialog(Forms.Context.MainWindow) { Title = DialogTitle }; dialog.InitializeDatePicker(Element.Date, Element.MinimumDate, Element.MaximumDate); dialog.DateTimeChanged += DialogDateTimeChangedHandler; dialog.Dismissed += DialogDismissedHandler; dialog.Show(); } void DialogDateTimeChangedHandler(object sender, Native.DateChangedEventArgs dcea) { Element.Date = dcea.NewDate; _realControl.Text = dcea.NewDate.ToString(Element.Format); } void DialogDismissedHandler(object sender, EventArgs e) { var dialog = sender as Native.DateTimePickerDialog; dialog.DateTimeChanged -= DialogDateTimeChangedHandler; dialog.Dismissed -= DialogDismissedHandler; } void UpdateDate() { _realControl.Text = Element.Date.ToString(Element.Format); } void UpdateTextColor() { _realControl.TextColor = Element.TextColor.ToNative(); } } }