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

How do I change the text color of an event?

2 Answers 76 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Craig
Top achievements
Rank 1
Craig asked on 16 Jun 2015, 05:07 PM

I'm evaluating the xamarin version of the telerik calendar and I've been struggling with styling events. There seem to be examples of how to change the shape of an event, but when I implement those examples, the text of the event goes away. There also does not seem to be any way to globally set this for all events. so here's what I'm doing so far:

RadCalendarView calendarView = FindViewById<RadCalendarView>(Resource.Id.calendarView);

calendarView.Adapter.Style = Com.Telerik.Widget.Calendar.CalendarStyles.MaterialDark(this);                

which sets the style mostly how I want, but the text is black of the events and I want it to be white. so I overrode the EventRenderer and that's when the text goes away.

        public class MyEventRenderer : EventRenderer
        {
            private Paint paint;

            public MyEventRenderer(Context context)
                : base(context)
            {
                paint = new Paint();
                paint.AntiAlias = true;
            }

            public override void RenderEvents(Android.Graphics.Canvas canvas, CalendarDayCell cell)
            {
                int desiredOffset = 20;
                int shapeRadius = 10;
                int locationX = cell.Left + 20;
                int locationY = cell.Top + 50;

                cell.TextColor = Android.Graphics.Color.ParseColor("#FFFFFF");

                foreach (Event e in cell.Events)
                {
                    this.paint.Color = new Android.Graphics.Color(e.EventColor);
                    canvas.DrawCircle(locationX, locationY, shapeRadius, this.paint);
                    locationY += shapeRadius + desiredOffset;
                }
            }
        }

Please let me know what I'm missing. thanks, Craig

2 Answers, 1 is accepted

Sort by
0
Accepted
Todor
Telerik team
answered on 19 Jun 2015, 08:00 AM
Hi Craig,

Thank you for your interest in RadCalendarView.

The EventRenderer is responsible for all the information about the events that will be drawn including the text. Since in your method you only draw a circle it is expected that there is no text. Here's an example where you draw not only a circle but also text for each event:

foreach (Event e in cell.Events)
{
    this.paint.Color = new Android.Graphics.Color(e.EventColor);
    canvas.DrawCircle(locationX, locationY, shapeRadius, this.paint);
    locationY += shapeRadius + desiredOffset;
    canvas.DrawText (e.Title, textLocationX, textLocationY, paint);
}

Of course, you can use text locations and paint of your choice, which don't need to be the same for the text and the circle.

I hope this information helps.

Regards,
Todor
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
Craig
Top achievements
Rank 1
answered on 19 Jun 2015, 01:08 PM
Exactly what I needed! That worked perfectly. thanks.
Tags
Calendar
Asked by
Craig
Top achievements
Rank 1
Answers by
Todor
Telerik team
Craig
Top achievements
Rank 1
Share this question
or