Forum Xamarin.Forms

DatePicker Date Property

JordanMazurke.5220JordanMazurke.5220 USMember
edited April 2015 in Xamarin.Forms

I have written a custom renderer for iOS for a subclass of DatePicker.

The issue I am seeing is that the first time a date selection is made, the bindable property Date is actually been set to the previous day. This only happens on the first selection - any further selections result in the correct date.

Has anybody seen this behaviour exhibited and if so, how did you overcome it.



  • MitchMilamMitchMilam USMember ✭✭✭

    @JordanMazurke.5220 can you show us your renderer code?

  • The basics of the functionality is handled in the following method which is called from the OnElementPropertyChanged method.

    void UpdateDate()
                var date = Element.Date;
                _picker.Date = date.ToNSDate();
                if (DateTime.Compare(new DateTime(1900, 1, 1), date.Date) == 0 || DateTime.Compare(DateTime.Now.Date, date.Date.Date) == 0)
                    Control.Text = "";
                    var formattedStringDate = NSDateFormatter.ToLocalizedString(date.ToNSDate(), NSDateFormatterStyle.Medium, NSDateFormatterStyle.None);
                    Control.Text = formattedStringDate;

    I have a internal requirement to blank out the date when it is equal to today or the default date for the database variant we use.

    Other than this initial selection, it works exactly as required.


Sign In or Register to comment.