This is a migrated thread and some comments may be shown as answers.

Binding DatePicker and TimePicker to DateTime

1 Answer 607 Views
TimePicker and TimeSelector
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nolan
Top achievements
Rank 1
Nolan asked on 17 May 2013, 11:17 PM

Is there a way to bind the DatePicker and the TimePicker to a single DateTime object so that the date of the DateTime object will be the date from the DatePicker, and the time from the DateTime object will be the selected time in the TimePicker? Currently, selecting a date from the DatePicker will make the DateTime object the selected date from the picker, and the current time. Then if you select the time from the TimePicker, it will change the DateTime object to the current date, and the selected time.

Here is an example:
XAML:

<StackPanel Orientation="Vertical">
     <telerikInput:RadDatePicker Value="{Binding ReminderDate, Mode=TwoWay}" />
     <telerikInput:RadTimePicker Value="{Binding ReminderDate, Mode=TwoWay}" />
</StackPanel>


C#:

public partial class TestPage : PhoneApplicationPage
{
     public Example examp = new Example();
 
     public TestPage()
     {
          InitializeComponent();
          this.DataContext = examp;
     }   
}
 
public class Example
{
     public Example()
     {
          ReminderDate = new DateTime();
     }
 
     public DateTime ReminderDate { get; set; }
}

 

STEPS TO PRODUCE:
Assume that the current date is 5/1/2013 at 4:12 PM

1. Select a date (say 5/20/2013). Now the ReminderDate = 5/20/2013 4:12PM
2. Select a time (say 10:30PM). Now the ReminderDate = 5/1/2013 10:30PM

How can I make it so when it does two-way binding, it gets: 5/20/2013 10:30PM, or do I have to do this through code?

Thank you,
    -Nolan

1 Answer, 1 is accepted

Sort by
0
Accepted
Deyan
Telerik team
answered on 21 May 2013, 07:19 AM
Hi Nolan,

The code you've pasted here is correct. You will only need to implement the INotifyPropertyChanged interface on your business object and fire the PropertyChanged event each time the DateTime property is set with different value.

This works on my side.

I hope this helps.

Regards,
Deyan
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
TimePicker and TimeSelector
Asked by
Nolan
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Share this question
or