This is a migrated thread and some comments may be shown as answers.
SelectedDate is not "highlighted" on iOS, when changing iOS *Calendar.Locale*
3 Answers 26 Views
This is a migrated thread and some comments may be shown as answers.
Namysław
Top achievements
Rank 1
Namysław asked on 08 Mar 2018, 11:12 AM

 SelectedDate is not "highlighted" on iOS, when changing iOS *Calendar.Locale*

I'm using this solution - https://www.telerik.com/forums/calendar-does-not-change-first-day-of-week-according-to-current-culture#ZjdzTjeeFUaB-Ky7BAgirA - to set *RadCalendar* locale to current devide locale (maily to have different week starting day).
Changing of *Locale* itself working fine.

However it gives side effect, which is - *SelectedDate* is not "highlighted" on iOS, on initializing *RadCalendar*.

I found workaround for that, which is to set *SelectedDate = null* and then revert it back:

protected override void OnAppearing()
{
    // TODO - Temporary workaround for Telerik issue at iOS - *SelectedDate* is not setting selection in UI, for Appearing of Calendar (setting/changing date works fine)
    // Workaround is to fill temporary *DateTime* object with *SelectedDate*, then setting *null* to *SelectedDate*, and then restoring original date back on *SelectedDate* (SIC!)
    if (Device.RuntimePlatform == Device.iOS && Calendar.SelectedDate != null)
    {
        var cachedDateTime = Calendar.SelectedDate.Value;
        Calendar.SelectedDate = null;
        Calendar.SelectedDate = cachedDateTime;
    }
 
    base.OnAppearing();
}


It's working, but I would like to avoid such crappy workarounds.

App without setting *Locale* OR with setting *Locale* + above workaround:
- attached *rc1.png*

App with setting *Locale* + without above workaround:
- attached *rc2.png*

I'm also attaching simple reproducable project, with latest Telerik DLL release + latest XF nuget release:
- https://mega.nz/#!TZQxlJpD!1ORXQe7CFLXP7osu7vmWk_mmFgVlGQsOqZ2pED4teiI

3 Answers, 1 is accepted

Sort by
0
Namysław
Top achievements
Rank 1
answered on 08 Mar 2018, 11:14 AM
Just to clarify - solution from https://www.telerik.com/forums/calendar-does-not-change-first-day-of-week-according-to-current-culture#ZjdzTjeeFUaB-Ky7BAgirA is only extending **CalendarRenderer** and using two lines of code:

[assembly: ExportRenderer(typeof(RadCalendar), typeof(LocaleAwareRadCalendarRenderer))]
namespace App2.iOS
{
    public class LocaleAwareRadCalendarRenderer : CalendarRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<RadCalendar> e)
        {
            base.OnElementChanged(e);
 
            if (Control?.Calendar != null && Element != null)
            {
                Control.Calendar.Locale = NSLocale.CurrentLocale;
                Control.ReloadData();
            }
        }
    }
}
0
Nikolay
Telerik team
answered on 12 Mar 2018, 08:50 AM
Hello Namysław,

The issue you're observing is caused by calling the ReloadData() method of the native calendar control - after that method is called the visual selection indication of the calendar is lost. To solve this problem I can suggest another way to change the first day of the week without reloading the native calendar. Instead of setting new Locale to the existing NSCalendar you can create new NSCalendar instance and assign it to the TKCalendar control. Here is a simple code snipped of how we can achieve this:

protected override void OnElementChanged(ElementChangedEventArgs<RadCalendar> e)
{
    base.OnElementChanged(e);
 
    if (Control?.Calendar != null && Element != null)
    {
        NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);
        calendar.Locale = NSLocale.CurrentLocale;
 
        this.Control.Calendar = calendar;
    }
}


I hope this information helps.

Regards,
Nikolay
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
0
Namysław
Top achievements
Rank 1
answered on 12 Mar 2018, 01:12 PM
Hello Nikolay,
Thanks for that! It's working fine without my **cachedDateTime** workaround.

Thanks a lot!
Asked by
Namysław
Top achievements
Rank 1
Answers by
Namysław
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or