Chnage Color of Weekend Using XamForms.Controls.Calendar

TTWTTW Member ✭✭
edited December 3 in Xamarin.Forms

Now I am developing app Using Xamairn. In my Project I need to Change color of Satday and Sunday. Is there any way to Only Change Color of SaturdayDay and SunDay in XamForms.Controls.Calendar using Xamarin.
my app calenar design

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Is there any way to Only Change Color of SaturdayDay and SunDay in XamForms.Controls.Calendar using Xamarin.

    Do you mean the selected date's background color ?

    public partial class Page2 : ContentPage
    {
        Calendar c;
        public Page2()
        {
            InitializeComponent();
    
            c = new Calendar
            {
                BorderColor = Color.Gray,
                BorderWidth = 3,
                BackgroundColor = Color.Gray,
                StartDay = DayOfWeek.Sunday,
                StartDate = DateTime.Now,
                SelectedBorderColor = Color.Transparent,               
            };
    
            c.DateClicked += C_DateClicked;
    
            Content = c;
        }
    
        private void C_DateClicked(object sender, DateTimeEventArgs e)
        {
            if (e.DateTime.DayOfWeek == DayOfWeek.Saturday || e.DateTime.DayOfWeek == DayOfWeek.Sunday)   //weekend
            {
                c.SelectedBackgroundColor = Color.Red;
            }
            else
            {
                c.SelectedBackgroundColor = Color.Blue;
            }
        }
    }
    

  • TTWTTW Member ✭✭

    I want to Change Saturday and Sunday Text Color to Gray

  • ColeXColeX Member, Xamarin Team Xamurai

    @TTW said:
    I want to Change Saturday and Sunday Text Color to Gray

    Well , it's a bit of complicated , you have to pick the weekends in a certain month , and set them as Specific Dates !

    Code

    public partial class Page2 : ContentPage
    {
        Calendar c;
        public Page2()
        {
            InitializeComponent();
    
            c = new Calendar
            {
                BorderColor = Color.Gray,
                BorderWidth = 3,
                BackgroundColor = Color.Gray,
                StartDay = DayOfWeek.Monday,
                StartDate = DateTime.Now,
                SelectedBorderColor = Color.Transparent,  
                WeekdaysTextColor = Color.Purple
            };
    
            c.LeftArrowClicked += C_LeftArrowClicked;
            c.RightArrowClicked += C_RightArrowClicked;
    
            Content = c;
    
    
            var now = DateTime.Now;
            var month = now.Month;
            while (now.Month == month)
            {
                now = now.AddDays(-1);
            }
            now = now.AddDays(1);
            pickUpWeekendInMonth(now);
    
        }
    
        private void C_RightArrowClicked(object sender, DateTimeEventArgs e)
        { 
            pickUpWeekendInMonth(e.DateTime);
        }
    
        private void C_LeftArrowClicked(object sender, DateTimeEventArgs e)
        {
            pickUpWeekendInMonth(e.DateTime);
        }
    
    
        private void pickUpWeekendInMonth(DateTime e)
        {
            var list = new List<SpecialDate>();
    
            var firstDay = e;
    
            var month = firstDay.Month;
    
            while (firstDay.Month == month)
            {
                if (firstDay.DayOfWeek == DayOfWeek.Saturday || firstDay.DayOfWeek == DayOfWeek.Sunday)
                {
                    list.Add(new SpecialDate(firstDay) { TextColor = Color.Gray });
                }
    
                firstDay = firstDay.AddDays(1);
            }
    
            c.SpecialDates = list;
        }
    
    }
    

Sign In or Register to comment.