New to Telerik UI for Xamarin? Download free 30-day trial

How to access Calendar TodayCellStyle and SelectedCellStyle in iOS custom renderer

Environment

Product Version 2020.2.513.1
Product Calendar for Xamarin Cross-Platform

Description

This help article will show you how to access calendar properties set in Xamarin.Forms inside the Custom Renderer

Solution

You will need to pass the Element from the Renderer to the Delegate:

Example

Here is a sample Calendar definition in XAML with TodayCellStyle and SelectedCellStyle properties set:

<telerikInput:RadCalendar>
    <telerikInput:RadCalendar.SelectedCellStyle>
        <telerikInput:CalendarCellStyle BorderColor="Transparent" BackgroundColor="Gray" TextColor="White"/>
    </telerikInput:RadCalendar.SelectedCellStyle>
    <telerikInput:RadCalendar.TodayCellStyle>
        <telerikInput:CalendarCellStyle  BorderColor="Transparent" BackgroundColor="White" TextColor="Gray"/>
    </telerikInput:RadCalendar.TodayCellStyle>
</telerikInput:RadCalendar>

and the custom renderer implementation for iOS

public class CustomCalendarRenderer : CalendarRenderer
{
    protected override CalendarDelegate CreateCalendarDelegateOverride()
    {
        return new CustomCalendarDelegate(this.Element);
    }
}

public class CustomCalendarDelegate : CalendarDelegate
{
    private RadCalendar element;

    public CustomCalendarDelegate(RadCalendar element) : base()
    {
        this.element = element;
        SetDisplaySelectionDecoration(false);
    }
    public override void UpdateVisualsForCell(TKCalendar calendar, TKCalendarCell cell)
    {
        var dayCell = cell as TKCalendarDayCell;
        // here is how we can get the TodayCellStyle and SelectedCellStyle
        var cellColor = element.TodayCellStyle.BackgroundColor.ToUIColor();
        var cellSelectedColor = element.SelectedCellStyle.BackgroundColor.ToUIColor();
    }
}
In this article
Not finding the help you need? Improve this article