We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Change Day Color based on number of Events

Hi All,

Is it possible to change the color of the day depending on how many events there are in Month view?

For example if there are no events for a given day the background color for the day would be green.

3 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team March 1, 2019 07:32 AM UTC

Hi Guy, 
 
Thank you for contacting Syncfusion support. 
 
Based on the provided information, your requirement of “Customizing the Month cell background color based on the appointment availability on the specific day” in Calendar Xamarin.Forms can be achieved using OnMonthCellLoaded event. Using this event, you can customize Text, Backgroud, Border color and Font by using MonthCellLoadedEventArgs argument. 
 
Please refer the following code for your reference, 
 
[C#]
        calendar.OnMonthCellLoaded += Calendar_OnMonthCellLoaded;
 
         
        private void Calendar_OnMonthCellLoaded(object sender, MonthCellLoadedEventArgs args) 
        { 
            // As default setting Month cell Background color as Green 
            args.BackgroundColor = Color.Green; 
            appointments = calendar.DataSource as CalendarEventCollection; 
 
            for (int i = 0; i < appointments.Count; i++) 
            { 
                var appointment = appointments[i]; 
                if (args.Date.Date == appointment.StartTime.Date) 
                { 
                    // Setting Background color when the appointment available on specific day 
                    args.BackgroundColor = Color.Red; 
                } 
            }            
        } 
 
We have prepared sample based on your requirement, 
 
 
In the sample, we have set month cell Background color as Red for the appointment available days and set Green for the no events days. 
 
Regards,
Subburaj Pandian V 
 



GU Guy March 1, 2019 10:00 AM UTC

Hi Subburaj,

Thank you for that it works like a charm, I'm simplified it for my needs to the below.


private void Calendar_OnMonthCellLoaded(object sender, MonthCellLoadedEventArgs args)
        {
            if ((calendar.DataSource as CalendarEventCollection).All(x => x.StartTime.Date != args.Date.Date))
                args.BackgroundColor = Color.LightGreen;
        }



SP Subburaj Pandian Veluchamy Syncfusion Team March 1, 2019 10:02 AM UTC

Hi Guy,  
  
Thank you for the update. We are happy that the given solution meets your requirement. 
 
Please let us know, if you need any further assistance.  
 
Regards,
Subburaj Pandian V  


Loader.
Live Chat Icon For mobile
Up arrow icon