Unplanned
Last Updated: 02 Sep 2019 08:36 by ADMIN
John
Created on: 24 Jun 2019 12:13
Category: Calendar & Scheduling
Type: Feature Request
4
Selected Date is not preserved when switching viewmodes
When you switch from Day/Week modes to Month -> the selected date is preserved. However, the other way around does not work.
Attached Files:
7 comments
ADMIN
Stefan Nenchev
Posted on: 02 Sep 2019 08:36
Hello, John, Bhavin,

I have already answered to Bhavin directly in a ticket he has raised with us, but I am leaving some more information here as well.

The workaround suggested to John seems to work for Android only. Here is an additional workaround which should work for iOS as well.
  • Introduce a field where you will store the last selected date when in Month View mode.
  • Update this field on SelectionChanged when you are in Month View mode.
  • When you switch view modes from Month to Day, check whether you have stored any value in the field and if so - apply it once the ViewMode is already changed(through Dispatcher).

Here is the actual implementation:

private DateTime? preservedSelectedDate;
         
private void Calendar_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "ViewMode")
            {
                if ((calendar.ViewMode == CalendarViewMode.Day || calendar.ViewMode == CalendarViewMode.MultiDay) && this.preservedSelectedDate != null)
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        calendar.SelectedDate = this.preservedSelectedDate;
                        calendar.DisplayDate = (DateTime)this.preservedSelectedDate;
                        this.preservedSelectedDate = null;
                    });
                }
            }
        }
  
private void Calendar_SelectionChanged(object sender, Telerik.XamarinForms.Common.ValueChangedEventArgs<object> e)
        {
            if (calendar.ViewMode == CalendarViewMode.Month)
            {
                this.preservedSelectedDate = calendar.SelectedDate.Value;
            };
        }

I hope the additional information will be helpful for you both until we come up with a permanent fix.

Have a great week.

Regards,
Stefan Nenchev
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
Steve
Posted on: 29 Aug 2019 15:44

Hi John,

 I see what you are saying. When I started using Calendar, I assumed that we have to bind SelectionChanged event to calendar for it to work. I always had the workaround you are suggesting in my event.  It worked. But now it has stopped working also.

And that's the problem.

 

Bhavin

John
Posted on: 28 Aug 2019 20:07

Here's the original bug i found when looking for this issue: https://www.telerik.com/forums/maintain-selecteddate-when-change-viewmodes. It is from April.

 

This thread here was created 24 June 2019. Both are older than a month. I've been seeing this issue for at least 8 months and finally decided to try to track down in answer which lead to all of this.

Steve
Posted on: 28 Aug 2019 19:51

Work around doesn't work. I didn't see this issue a month back. That's when I integrated the calendar. So it's gotta be something new. 

 

John
Posted on: 28 Aug 2019 16:33

Here was the response from Stefan:

 

Hello, John,

Thank you for the patience.

Reviewing the behavior further, it seems to be caused due to the reason that in Day/Week views - the DisplayDate of the native calendar is automatically synced when the SelectedDate is changed. On the other hand, when you change the selection in the month view - the display date is not always updated. I have logged the overall behavior as a bug at our end and you can track its progress on the following link from our Ideas & Feedback portal - Selected Date is not preserved when switching view modes. I have also added 1000 points to your account for reporting the behavior.

In the meantime, a straightforward workaround is to manually update the DisplayDate when you change the SelectedDate when in month view:

private void Calendar_SelectionChanged(object sender, Telerik.XamarinForms.Common.ValueChangedEventArgs<object> e)
{
    if (calendar.SelectedDate.HasValue)
    {
        calendar.DisplayDate = calendar.SelectedDate.Value;
    };
}

Give it a try in your actual application and, if it works as expected, consider using it until we come up with a permanent fix. In case you observe issues with the approach, please report it so we can consider them.

I am looking forward to your reply.

Have a great week.

Regards,
Stefan Nenchev
Progress Telerik
John
Posted on: 28 Aug 2019 16:31
They offered a work around for this by setting the DisplayDate/SelectedDate (not sure which since it's been a while) in the code behind instead of using the binding, but the work around did not fix the issue either. i don't believe rolling back to the previous version will help you because this issue has existed for quite some time. like over a year that i'm aware of.
Steve
Posted on: 28 Aug 2019 15:38

Hello, Any update on this issue. Should we roll back to older version which doesn't have this issue?

We need to go live in few days with Testing. This is not acceptable.

 

Thanks

Bhavin