Override Renderer

9 posts, 0 answers
  1. Victor
    Victor avatar
    17 posts
    Member since:
    Jun 2011

    Posted 17 Mar 2015 Link to this post

    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..?
  2. Rosy Topchiyska
    Admin
    Rosy Topchiyska avatar
    550 posts

    Posted 20 Mar 2015 Link to this post

    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.

     
  3. DevCraft banner
  4. Victor
    Victor avatar
    17 posts
    Member since:
    Jun 2011

    Posted 20 Mar 2015 in reply to Rosy Topchiyska Link to this post

    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.
  5. Lewis
    Lewis avatar
    8 posts
    Member since:
    Feb 2015

    Posted 24 Mar 2015 Link to this post

    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
  6. Victor
    Victor avatar
    17 posts
    Member since:
    Jun 2011

    Posted 24 Mar 2015 in reply to Lewis Link to this post

    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());
           }
     
            
       }
  7. Lewis
    Lewis avatar
    8 posts
    Member since:
    Feb 2015

    Posted 25 Mar 2015 in reply to Victor Link to this post

    That's great, thank you.
  8. Fabio
    Fabio avatar
    20 posts
    Member since:
    Apr 2015

    Posted 08 May 2015 in reply to Victor Link to this post

    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
        {
        }

  9. Victor
    Victor avatar
    17 posts
    Member since:
    Jun 2011

    Posted 08 May 2015 in reply to Fabio Link to this post

    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()
            {
                 
            }
     
             
        }

     

  10. Fabio
    Fabio avatar
    20 posts
    Member since:
    Apr 2015

    Posted 08 May 2015 in reply to Victor Link to this post

    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;
                }
                 
            }
        }
    }

Back to Top
DevCraft banner