sfCalendar blackoutdates

Hi,

I would like to use the sfcalendar blackoutdates in xamarin Forms. I need to blackoutdates on all Sunday's and also other local holidays. I tried many times, it's not working. Kindly give me some samples for this asap. 


5 Replies 1 reply marked as answer

SS SaiGanesh Sakthivel Syncfusion Team September 2, 2021 10:33 AM UTC

Hi Muthu, 
 
Thank you for using syncfusion products. 
 
#Regarding SfCalendar blackoutdates 
We have checked the reported query from our end. we would like to inform you that you can achieve your requirement with help of OnMonthCellLoaded event. Please refer to the following code snippet for your reference. 
 
Code snippet 
//// Add local holidays leave as BlackoutDates 
List<DateTime> black_Dates = new List<DateTime>(); 
black_Dates.Add(new DateTime(2021, 09, 10)); 
black_Dates.Add(new DateTime(2021, 10, 19)); 
black_Dates.Add(new DateTime(2021, 08, 20)); 
black_Dates.Add(new DateTime(2021, 02, 21)); 
black_Dates.Add(new DateTime(2021, 04, 22)); 
black_Dates.Add(new DateTime(2021, 03, 23)); 
black_Dates.Add(new DateTime(2021, 05, 24)); 
black_Dates.Add(new DateTime(2021, 11, 25)); 
black_Dates.Add(new DateTime(2021, 12, 26)); 
black_Dates.Add(new DateTime(2021, 01, 27)); 
calendar.BlackoutDates = black_Dates; 
calendar.OnMonthCellLoaded += Calendar_OnMonthCellLoaded;

private void Calendar_OnMonthCellLoaded(object sender, MonthCellLoadedEventArgs e) 
{ 
    var blackoutDates = new List<DateTime>(); 
    //// Add every sunday and saturday as BlackoutDates 
    if (e.Date.DayOfWeek == DayOfWeek.Sunday || e.Date.DayOfWeek == DayOfWeek.Saturday) 
    { 
        if (this.calendar.BlackoutDates != null) 
        { 
            blackoutDates = (List<DateTime>)this.calendar.BlackoutDates; 
        } 
        blackoutDates.Add(e.Date); 
        this.calendar.BlackoutDates = blackoutDates; 
    } 
} 
 
Please refer to the tested sample in the following locations for your reference. 
 
output 
 
 
Please let us know if you have any concerns. 
 
Regards,
SaiGanesh Sakthivel
 



MK Muthu Kumar replied to SaiGanesh Sakthivel September 3, 2021 06:59 AM UTC

Thank you.


I have another issues. When i select the dates in Xamarin Calendar using Selection Range. I would like to show the no of days. If it's sunday and local holidays has been blocked. Saturday as 0.5 days for this calculation. I tried in many ways, but it's no use. Kindly help me to solve this issues.



MS Muniappan Subramanian Syncfusion Team September 6, 2021 09:59 AM UTC

Hi Muthu,  
 
Thank you for the update. 
 
We checked your requirement “I would like to show the no of days. If it's sunday and local holidays has been blocked. Saturday as 0.5 days for this calculation" and You can achieve your requirement by using the SelectionChanged event in SfCalendar. We’ve prepared the sample for the same. Please find the link below for the sample, 
 
Code Snippet: 
private void Calendar_SelectionChanged(object sender, Syncfusion.SfCalendar.XForms.SelectionChangedEventArgs e) 
{ 
    double noOfDays = e.DateAdded.Count; 
    double count = 0; 
 
    foreach (var item in e.DateAdded) 
    { 
        if (item.Date.Date.DayOfWeek == DayOfWeek.Saturday) 
        { 
            count = +0.5; 
        } 
    } 
 
    noOfDays = noOfDays - count; 
 
    App.Current.MainPage.DisplayAlert("Selected Days", noOfDays.ToString() + " Days", "ok"); 
} 
 
 
Please find the output for the same, 
 
 
We hope that this helps you, kindly revert us if you have any concern.  
 
Regards, 
Muniappan S. 


Marked as answer

MK Muthu Kumar September 7, 2021 03:16 AM UTC

Thank You.



SS SaiGanesh Sakthivel Syncfusion Team September 7, 2021 07:23 AM UTC

Hi Muthu, 
 
Thank you for the update. 
 
We are glad to know that our solution meets your requirement. Please let us know if you need any further assistance. 
 
Regards,
SaiGanesh Sakthivel
 


Loader.
Up arrow icon