telerikInput:RadTimePicker bind its selection to view model

1 Answer 210 Views
TimePicker
Daniel
Top achievements
Rank 1
Silver
Bronze
Daniel asked on 15 Mar 2022, 01:45 PM | edited on 15 Mar 2022, 02:18 PM

Hi,

1. I'm using <telerikInput:RadTimePicker  />,

2. I want to bind it selection to view model

and set its value in the view model's constructor to current time.

3. I want also to know how to set its format only to show hours .

Thanks,

 

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 18 Mar 2022, 07:59 AM

Hello,

Example with binding the Time property of the RadTimePicker:

        <telerikInput:RadTimePicker Time="{Binding SelectedTime, Mode=TwoWay}"/>

ViewModel:

public class ViewModel : INotifyPropertyChanged
{
    private TimeSpan? selectedTime;
    public ViewModel()
    {
        this.SelectedTime = new TimeSpan(1, 2, 3, 4);
    }
    public TimeSpan? SelectedTime
    {
        get { return this.selectedTime; }
        set
        {
            if (this.selectedTime != value)
                this.selectedTime = value;
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedTime"));

        }
    }
}

Regards,
Didi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TimePicker
Asked by
Daniel
Top achievements
Rank 1
Silver
Bronze
Answers by
Didi
Telerik team
Share this question
or