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

SelectedDate ignored when TrySetViewMode

2 Answers 54 Views
Calendar & Scheduling
This is a migrated thread and some comments may be shown as answers.
IanV
Top achievements
Rank 1
Veteran
IanV asked on 10 Jan 2019, 07:02 PM

Bug?

See attached gif video

Newst Xamarin, Newest Telerik

 

When the Calendar control is in Month view, I wish to switch to Day view when a date is selected.

The view changes, but the Day view doesn't scroll to the selected date

If I am at January 10th (Month View), then go to March 30th (Day view), the Day view shows March, but shows the week containing the 10th , not the 30th

My RadCalendar is bound to a model.

 

<input:RadCalendar x:Name="calendar" SelectedDate="{Binding SelectedDate, Mode=TwoWay}"

 

In the code behind I do this.

private void Calendar_OnSelectionChanged(object sender, ValueChangedEventArgs<object> e)
{
    if (calendar.ViewMode == CalendarViewMode.Month)
    {
        calendar.TrySetViewMode(CalendarViewMode.Day);
        Model.SelectedDate = (DateTime) e.NewValue;
    }
}

2 Answers, 1 is accepted

Sort by
0
IanV
Top achievements
Rank 1
Veteran
answered on 10 Jan 2019, 07:29 PM

Solution.

Bind the view to the model for both SelectedDate and DisplayDate

SelectedDate="{Binding SelectedDate, Mode=TwoWay}"
DisplayDate="{Binding DisplayDate, Mode=TwoWay}"

 

Then in the xaml code behind, set the DisplayDate to the SelectedDate. This will sync it up:

private void Calendar_OnSelectionChanged(object sender, ValueChangedEventArgs<object> e)
{
    if (calendar.ViewMode == CalendarViewMode.Month)
    {
        calendar.TrySetViewMode(CalendarViewMode.Day);
        Model.DisplayDate = Model.SelectedDate;
    }
}

 

0
Yana
Telerik team
answered on 15 Jan 2019, 09:17 AM
Hi Ian,

Indeed, that is the correct way to resolve this - you would need to sync DisplayDate property as well in order to show the correct dates range in DayView.

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
Tags
Calendar & Scheduling
Asked by
IanV
Top achievements
Rank 1
Veteran
Answers by
IanV
Top achievements
Rank 1
Veteran
Yana
Telerik team
Share this question
or