Forms Android Timepicker set timepicker's value

eric.6131eric.6131 USMember ✭✭

Hi,

I have a CustomTimePicker than extends TimePicker. The default Time of this picker in the view is DateTime.Now.TimeOfDay. The user cannot select a time prior to this time when opening the picker.

Thus far I can alert the user, but the TimePicker's Entry value is being set to what the user chooses in the TimePicker. I would like to reset this to the default value from when the TimePicker was opened. Here's where Im at so far:

'
public class TimePicker_Custom : TimePicker
{
private static TimeSpan _currentTime;

    public TimePicker_Custom(TimePickerCustomViewModel model)
    {
        this.PropertyChanged += timeChanged;
        this.Time = model.Time;
        this.Format = model.Format;
        _currentTime = model.Time;

    }

    private void timeChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {

            if (e.PropertyName == "Time")
            {
                var selTime = Time;
                if (selTime < _currentTime)
                {
                    var page = new ContentPage();
                    page.DisplayAlert("Time Error", "Please select a time in the future", "OK");

                    this.Value = _currentTime;  // how can I set the default time of the picker here?

                }
           // or let the picker set the time here, value is valid, which is does by default

            }

    }

    public static readonly BindableProperty ValueProperty =
                BindableProperty.Create<TimePicker_Custom, TimeSpan>(p => p.Value, default(TimeSpan));
    public TimeSpan Value
    {
        get
        {
            return (TimeSpan)GetValue(ValueProperty);
        }
        set
        {
            SetValue(ValueProperty, value);
        }
    }

}

'

Thanks in advance!

Sign In or Register to comment.