Reputation: 91
I have WPF Extended Toolkit 3.5.0 (by Xceed), I'm using DateTimePicker control from here. I want to know that how to get selected Values of Hours, Minutes, Seconds, DayofWeek, Day, Month separately by DateTimePicker. Before this I was using telerik DateTimePicker Control Here I was using this approach to get these values
hours= DTPicker.SelectedTime.Value.Hours;
minutes= DTPicker.SelectedTime.Value.Minutes;
seconds= DTPicker.SelectedTime.Value.Seconds;
//for date
dayofweek= DTPicker.SelectedDate.Value.DayOfWeek;
day= DTPicker.SelectedDate.Value.Day;
month= DTPicker.SelectedDate.Value.Month;
But I couldn't find SelectedDate/SelectedTime/SelectedValue properties here. Thanks
Upvotes: 0
Views: 616
Reputation: 175
Assume that you have named your Toolkit DateTiemPicker as DTPicker.
<toolkits:DateTimePicker Value="{Binding LastUpdated}" Format="FullDateTime" Width="200" Height="30" Name="DTPicker"/>
Then you can get all the value you need as below.
var seledtedDateTime = DTPicker.Value;
if (seledtedDateTime.HasValue)
{
var hours = seledtedDateTime.Value.Hour;
var minutes = seledtedDateTime.Value.Minute;
var seconds = seledtedDateTime.Value.Second;
var dayofweek = seledtedDateTime.Value.DayOfWeek;
var day = seledtedDateTime.Value.Day;
var month = seledtedDateTime.Value.Month;
}
Upvotes: 1
Reputation: 169370
The Value
property returns a DateTime?
:
DateTime? value = dateTimePicker.Value;
if (value.HasValue)
{
hours = value.Value.TimeOfDay.Hours;
minutes = value.Value.TimeOfDay.Minutes;
seconds = value.Value.TimeOfDay.Seconds;
//for date
dayofweek = value.Value.DayOfWeek;
day = value.Value.Day;
month = value.Value.Month;
}
You could basically just replace SelectedTime
by Value
in your current code.
Upvotes: 1