This is a migrated thread and some comments may be shown as answers.
NewValue Does Not Contain the Selected Date
2 Answers 4 Views
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 02 Jul 2019, 01:21 AM

My XAML is;

<telerikInput:RadCalendar
    x:Name="RunCalendar"
    Grid.Row="0"
    Grid.RowSpan="3"
    Grid.Column="0"
    Grid.ColumnSpan="3"
    HorizontalOptions="CenterAndExpand"
    VerticalOptions="CenterAndExpand"
    IsVisible="False"
    DisplayDate="{Binding CalendarDate}"
    MinDate="{Binding MinRunDate}"
    MaxDate="{Binding MaxRunDate}"
    SelectedDate="{Binding CalendarDate}"
    SelectionChanged="OnDateSelected"
    SelectionMode="Single" />

 

My code is;

private void OnCalendarClicked(object sender, EventArgs e)
{
    CalendarDate = RunDate;
    RunCalendar.IsVisible = true;
}
 
private void OnDateSelected(object sender, ValueChangedEventArgs args)
{
    DateTime newDate = DateTime.MinValue;
 
    try
    {
        newDate = DateTime.FromOADate(args.NewValue);
    }
    catch
    {
        //Ignore any error
    }
 
    DisplayRun(newDate);
}

 

When OnCalendarClicked is run the CalendarDate is being set to "7/2/2019" (today's date) however the value for newDate in OnDateSelected (which runs immediately after) is "1/1/0001".  However if I drill down into "args > base > NewValue" it is a DateTime value with the correct date.

How do I get the correct value for the date?

2 Answers, 1 is accepted

Sort by
0
Raymond
Top achievements
Rank 1
answered on 02 Jul 2019, 02:00 AM
Found the solution to this problem here.  I had to change the signature from;
private void OnDateSelected(object sender, ValueChangedEventArgs args)


to;
private void OnDateSelected(object sender, ValueChangedEventArgs<object> args)


The new and old values (NewValue and PreviousValue) now contain the correct values.
0
Yana
Telerik team
answered on 02 Jul 2019, 06:14 AM
Hi Raymond,

I am glad to hear you've managed to resolve  the case. 

Indeed, that's the correct event handler which provides the old and the new value after date selection. 
 
Let me know if I can help with anything else.

Regards,
Yana
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Asked by
Raymond
Top achievements
Rank 1
Answers by
Raymond
Top achievements
Rank 1
Yana
Telerik team
Share this question
or