wpftoolkit
wpftoolkit copied to clipboard
DateTimePicker - when Value is set the only date portion is shown on control but time part remains 12:00 AM
Hi, If you define a DatetimePicker like this: <xctk:DateTimePicker Value="2020/01/02"/> then yes, the default time part is 12:00 AM.
But if you define a DateTimePicker like this: <xctk:DateTimePicker /> and selects a date from the calendar, or by using the up/down buttons, the time part will use the current time.
Hi,
I put the value from the code behind. Something like this:
Xaml <xctk:DateTimePicker x:Name="dateTimePicker"/>
cs file dateTimePicker.Value = new DateTime(2020, 02 , 19, 23, 50, 11);
Using v3.8, I can see a DateTimePicker showing : "Wednesday, February 19, 2020 11:50:11 PM"
@XceedBoucherS I was able to reproduce this problem in v3.8.1.
If you put this in de cs file:
dateTimePicker.Value = new DateTime(2020, 02, 19, 23, 50, 11);
dateTimePicker.Value = new DateTime(2020, 02, 20, 0, 0, 0);
You should get 'Thursday, February 20, 2020 00:00:00". But when executing this code you will get 'Thursday, February 20, 2020 11:50:11 PM".
Hi TimKras, I installed Toolkit v3.8.1 via Nuget and this is my configuration: <StackPanel> <xctk:DateTimePicker x:Name="dateTimePicker"/> </StackPanel>
public MainWindow() { InitializeComponent();
dateTimePicker.Value = new DateTime( 2020, 02, 19, 23, 50, 11 );
dateTimePicker.Value = new DateTime( 2020, 02, 20, 0, 0, 0 );
}
Result is as expected : 'Thursday, February 20, 2020 00:00:00" I even tried using a button and on click setting the 2nd line: dateTimePicker.Value = new DateTime( 2020, 02, 20, 0, 0, 0 ); and it still worked.
Can you try this code. (both lines in the Click event).
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
dtp.Value = new DateTime(2020, 02, 19, 23, 50, 11);
dtp.Value = new DateTime(2020, 02, 20, 0, 0, 0);
}
Thank you for the tip, I was able to reproduce the bug. This only happens in code-behind, when modifying more than once the DateTimePicker.Value. It will be fixed in v4.1. In the meantime, I suggest you calculate the wanted dateTime and sets it once instead of calling dtp.Value many times.
Thank you.
Hi.
I'm having the same issue, but in my case value is binded to ViewModel value. Sometimes when property in viewModel is updated only the date portion in DateTimePicker changes, but the time portion remains unchanged.
So maybe you need to wait for v4.1 to have the fix.
If not, you can go in file Xceed.Wpf.Toolkit/DateTimePicker/Implementation/DateTimePicker.cs and:
- add a new bool variable
- in OnValueChanged() method, set the new variable to true before _calendar.SelectedDate and set if back to false after setting _calendar.DisplayDate.
- in Calendar_SelectedDatesChanged() method, modify "this.Value" only when the new variable is false.
It was under 4.0.1. Moving to 4.0.2 solved my problem.