4 Answers, 1 is accepted
Hi Scott,
Thank you for the provided details.
I am not sure what you mean here by saving the date. If I bind the SelectedValue property of the RadDateTimePicker to a property of type DateTime, the setter of the property is called each time when a new date is selected. Can you share your set-up so I can try to reproduce it on my side?
Regards,
Dinko
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).
Hi Dinko, I cannot provide you with my solution, however I am providing a couple of screen shots to see if that will help illustrate the issue. Note that in the first screen shot, date-1.jpg, I am just "textually" changing the date, not using the 9 square icon to select a date, or choosing the selection if it pops up. date-2.jpg illustrated how the date pops up if you textually change it.
If I click Save in my UI, it will not Save the date, and goes back to the previous one entered. Is this the way the RadDateTimePicker works, or is something wrong. Some of our users have complained that they don't want to select a date or use the 9 box, they just want to enter the date and click save.
Thank you!
Hello Scott,
Thank you for the provided details.
I understand what you mean here. You are right that editing the text will not update the bound value. The update will happen when the user presses the enter key or focus different element. What you can do to achieve this behavior is to subscribe to the ParseDateTimeValue event of the RadDateTimePicker. In the event handler, you can check the IsParsingSuccessful property from the event arguments. If the parsing is successful you can set the bound property to the Result property from the event arguments.
private void RadDateTimePicker_ParseDateTimeValue(object sender, Telerik.Windows.Controls.ParseDateTimeEventArgs args)
{
if(args.IsParsingSuccessful)
{
var newValue = args.Result;
var dateTimePicker = args.Source as RadDateTimePicker;
if((this.DataContext as ViewModel).MyDateProperty != args.Result)
{
this.MyDate = args.Result;
}
}
}
Regards,
Dinko
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/.
Hey Dinko, thanks a ton for sending me the sample code! While I had to make a few modifications, it worked!
For example, I had to make sure each RadDateTimePicker has an x:Name applied to it. In the code behind I made a small update. to get the code to work, I had to make a light adjustment for the args.Result. by referencing the SelectedDate parameter:
if ((this.DataContext as MyPrivateModelView).MyInternalVariable !=
args.Result)
{
this.MyCustomDateInXAML.SelectedDate = args.Result;
}