public class CustomDatePickerRender : DatePickerRenderer
{
public CustomDateTimePicker dtPicker;
public UIDatePicker input;
protected override void OnElementChanged(ElementChangedEventArgs<DatePicker> e)
{
base.OnElementChanged(e);
dtPicker = e.NewElement as CustomDateTimePicker;
if (Control!=null)
{
input = Control.InputView as UIDatePicker;
if (input != null && input.Mode != UIDatePickerMode.DateAndTime)
{
input.Mode = UIDatePickerMode.DateAndTime;
input.ValueChanged += Input_ValueChanged;
}
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == DatePicker.MinimumDateProperty.PropertyName)
{
if (input != null)
{
TimeZoneInfo estZone = TimeZoneInfo.Local;
DateTime date = DateTime.SpecifyKind(dtPicker.MiminumDT, DateTimeKind.Unspecified);
DateTime estTime = TimeZoneInfo.ConvertTimeFromUtc(date, estZone);
NSDate nSDate = Extensions.ToNSDate(estTime);
input.MinimumDate = nSDate;
}
}
else if (e.PropertyName == DatePicker.MaximumDateProperty.PropertyName)
{
if (input != null)
{
TimeZoneInfo estZone = TimeZoneInfo.Local;
DateTime date = DateTime.SpecifyKind(dtPicker.MaximunDT, DateTimeKind.Unspecified);
DateTime estTime = TimeZoneInfo.ConvertTimeFromUtc(date, estZone);
NSDate nSDate = Extensions.ToNSDate(estTime);
input.MaximumDate = nSDate;
}
}else if (e.PropertyName == DatePicker.IsFocusedProperty.PropertyName)
{
if (input != null)
{
TimeZoneInfo estZone = TimeZoneInfo.Local;
DateTime date = DateTime.SpecifyKind(dtPicker.CDT, DateTimeKind.Unspecified);
DateTime estTime = TimeZoneInfo.ConvertTimeFromUtc(date, estZone);
NSDate nSDate = Extensions.ToNSDate(estTime);
input.Date = nSDate;
}
}
}
private void Input_ValueChanged(object sender, EventArgs e)
{
if (Control != null)
{
var input = sender as UIDatePicker;
if (dtPicker != null)
{
DateTime date = input.Date.ToDateTime();
dtPicker.Date = date;
dtPicker.CDT = date;
}
}
}
}
}
But I want to use your component to have the same logic in Android and iOS. Can I develop with your component?