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

Override Renderer

8 Answers 139 Views
Calendar & Scheduling
This is a migrated thread and some comments may be shown as answers.
Victor
Top achievements
Rank 1
Victor asked on 17 Mar 2015, 08:15 PM
Is it possible to override the android renderer?
I've tried and failed (any samples?)

Short of this, is there any way to access the RadCalendarView to make styling changes directly, ie. CellDecorator..?

8 Answers, 1 is accepted

Sort by
0
Rosy Topchiyska
Telerik team
answered on 20 Mar 2015, 03:03 PM
Hello Victor,

Thank you for contacting us.

Unfortunately, in the current version of the calendar, you can not override the calendar renderer. Here is an article from our online documentation with several examples related to calendar styling. If you have any problems with customization of  the control, could you please share the details with us, and we will do our best to help you with the solution or this could give us some ideas of how to improve the calendar. We are also considering options to provide an entry point where you can access the native control.

Regards,
Rosy Topchiyska
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Victor
Top achievements
Rank 1
answered on 20 Mar 2015, 03:06 PM
I figured as much (through no lack of trying).  

I ended up writing my own view renderer which does give access to the native control (both TKCalendar and the RadCalendarView), which worked well enough to give me everything I need to customize.

Thanks for your help.
0
Lewis
Top achievements
Rank 1
answered on 24 Mar 2015, 04:42 PM
Hi Victor,
Would you mind outlining how you achieved this please?

I need access to the TKCalender control as i need to change properties on the presenter which are not exposed through the RadCalender class.

Thanks,

Lewis
0
Victor
Top achievements
Rank 1
answered on 24 Mar 2015, 04:52 PM
Not sure if this is the Telerik Approved way but it worked (here is the iOS renderer):


public class AppointmentCalendarRenderer : ViewRenderer<
AppointmentCalendar, TKCalendar>
   {
       AppointmentCalendar calendar;
       TKCalendar calendarView;
       AppointmentCalendarDelegate calendarDelegate;
 
       protected override void OnElementChanged(ElementChangedEventArgs<AppointmentCalendar> e)
       {
 
           try
           {
               base.OnElementChanged(e);
 
               if (e.NewElement == null)
                   return;
 
               this.calendar = e.NewElement;
               this.calendarView = new TKCalendar(this.Bounds);
               this.calendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
               this.calendarView.MinDate = this.calendar.MinDate.ToNSDate();
               this.calendarView.MaxDate = this.calendar.MaxDate.ToNSDate();
               this.calendarDelegate = new AppointmentCalendarDelegate();
               this.calendarView.Delegate = this.calendarDelegate;
               this.calendarDelegate.SelectionChanged += calendarDelegate_SelectionChanged;
                
               SetNativeControl(this.calendarView);
           }
 
 
           catch(Exception ee)
           {
                
           }
       }
 
       void calendarDelegate_SelectionChanged(object sender, ValueChangedEventArgs<object> e)
       {
           this.calendar.SelectedDate = (DateTime?)e.NewValue;
            
 
 
       }
   }
 
   public class AppointmentCalendarDelegate : TKCalendarDelegate
   {
       public event EventHandler<ValueChangedEventArgs<object>> SelectionChanged;
       private DateTime? previousDisplayDate;
       public void Dispose()
       {
       }
 
       public IntPtr Handle
       {
           get
           {
               return default(IntPtr);
           }
       }
 
       public override void UpdateVisualsForCell(TKCalendar calendar, TKCalendarCell cell)
       {
           if (cell is TKCalendarDayCell)
           {
               TKCalendarDayCell dayCell = (TKCalendarDayCell)cell;
                
               if ((dayCell.State & TKCalendarDayState.Selected) != 0)
               {
                   cell.Style.TextColor = UIColor.White;
                   cell.Style.ShapeStroke = new TKStroke (UIColor.FromRGB(229, 81, 19),7);
                   cell.Style.ShapeFill = new TKSolidFill (UIColor.FromRGB(229, 81, 19));
                    
                    
               }
 
               if ((dayCell.State & TKCalendarDayState.Today) != 0)
               {
                   cell.Style.TextColor = UIColor.Black;
                    
               }
           }
           
       }
 
       public override void DidSelectDate(TKCalendar calendar, NSDate date)
       {
            
           EventHandler<ValueChangedEventArgs<object>> eventHandler = this.SelectionChanged;
           if (eventHandler != null)
           {
               eventHandler(this, new ValueChangedEventArgs<object>((object)this.previousDisplayDate, (object)new DateTime?(date.ToDateTime())));
           }
           previousDisplayDate =new DateTime?( date.ToDateTime());
       }
 
        
   }
0
Lewis
Top achievements
Rank 1
answered on 25 Mar 2015, 09:30 AM
That's great, thank you.
0
Fabio
Top achievements
Rank 1
answered on 08 May 2015, 02:43 PM

Hello Victor

 I've checked you renderer, but would you mind explaining this classes please?

ViewRenderer<AppointmentCalendar, TKCalendar>

TKCalendar = RadCAlendar?

AppointmentCalendar = The class to inherit from your shared project? for example

public class CustomCalendar : RadCalendar
    {
    }

0
Victor
Top achievements
Rank 1
answered on 08 May 2015, 02:50 PM

If I understand your question correctly---

TKCalendar is the name of the iOS class for RadCalendar :

http://docs.telerik.com/devtools/ios/api/Classes/TKCalendar.html

And your assumption about AppointmentCalendar is correct.  

 All it is in the shared project is this:

 

public class AppointmentCalendar: RadCalendar
    {
        public AppointmentCalendar():base()
        {
             
        }
 
         
    }

 

0
Fabio
Top achievements
Rank 1
answered on 08 May 2015, 10:07 PM

Thanks a lot it worked! (Android version)

using System;
using X.Droid;
using X.Renderers;
using Telerik.XamarinForms.Input;
using Telerik.XamarinForms.InputRenderer.Android;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using Com.Telerik.Widget.Calendar;
 
 
[assembly: ExportRenderer(typeof(CustomCalendar), typeof(CustomCalendarRenderer))]
 
namespace X.Droid
{
    public class CustomCalendarRenderer : ViewRenderer<CustomCalendar, RadCalendarView>
    {
        protected override void OnElementChanged(ElementChangedEventArgs<CustomCalendar> e)
        {
            CustomCalendar calendar;
            RadCalendarView calendarView;
 
            try
            {
                base.OnElementChanged(e);
 
                if (e.NewElement == null)
                    return;
 
                calendar = e.NewElement;
                calendarView = new RadCalendarView(Forms.Context);
 
                SetNativeControl(calendarView);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw;
            }
             
        }
    }
}

Tags
Calendar & Scheduling
Asked by
Victor
Top achievements
Rank 1
Answers by
Rosy Topchiyska
Telerik team
Victor
Top achievements
Rank 1
Lewis
Top achievements
Rank 1
Fabio
Top achievements
Rank 1
Share this question
or