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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Change Day Color based on number of Events

Thread ID:

Created:

Updated:

Platform:

Replies:

143015 Feb 28,2019 02:19 PM UTC Mar 1,2019 10:02 AM UTC Xamarin.Forms 3
loading
Tags: SfCalendar
Guy
Asked On February 28, 2019 02:19 PM UTC

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.

Subburaj Pandian Veluchamy [Syncfusion]
Replied On 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 
 


Guy
Replied On 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;
        }


Subburaj Pandian Veluchamy [Syncfusion]
Replied On 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  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon