rebeccaXam / XamForms.Controls.Calendar

Custom calendar control for Xamarin.Forms. Customizable border thickness, color, background colors and formats. Version 1.0.8 or lower Built against: 2.1.0.6521 Version 1.1.0 or above Built against: 2.3.4.231
MIT License
132 stars 69 forks source link

Disable deselection and allow selection of different dates? #68

Open ali-h2010 opened 6 years ago

ali-h2010 commented 6 years ago

First of all, I would like to thank every person who contributed to create and maintain this great component.

I have 2 questions

Is this possible without changing the source code? any help will be appreciated.

Brighthui commented 6 years ago

Hi Ali,

For disable deselection, you may set SpecialDate property "Selectable = false".

I don't know how to remove borders.

ali-h2010 commented 6 years ago

Hi Brighthui, Thanks for your reply. Can you Kindly demonstrate how to do this in Xamal or the Code behind? I only have specialDates property which takes a list.

ali-h2010 commented 6 years ago

Sorry for the noob question @Brighthui this is all what I tried: XamForms.Controls.SpecialDate test = new XamForms.Controls.SpecialDate(DateTime.Today); test.Selectable = false;

It's not working though

ali-h2010 commented 6 years ago

I added the above special date, but I can still deselect dates calendar.SpecialDates.Add(test);

This only made today's date unelectable

ali-h2010 commented 6 years ago

I was able to remove the deselection by commenting the condition that checks if the date is selected in the file Calendar.Selected.cs

//if (button.IsSelected) //{ // ResetButton(button); //} //else //{ SelectedDates.Add(SelectedDate.Value.Date); var spD = SpecialDates?.FirstOrDefault(s => s.Date.Date == button.Date.Value.Date); SetButtonSelected(button, spD); //}

But now, how can I create the package or use the updated code on my project? any help will be appreciated.

ali-h2010 commented 6 years ago

I am not sure what i did differently but the solution above is not working. I lost the source for the code that i modified to remove deselection. I only have the nuget package. Can someone help please

ali-h2010 commented 6 years ago

I added this code `if (!date.HasValue) return false;

        if (SelectedDates.Count()>0)//check if there is a selected date
        {
            int result = DateTime.Compare((System.DateTime)date, SelectedDates[0]);
            if (result == 0)//Equal Dates
            {
                return false;
            }
        }`

in the Calendar.Selected.cs and commented the line in DateClickedEvent in calendar.cs as the following: protected void DateClickedEvent(object s, EventArgs a) { var selectedDate = (s as CalendarButton).Date; if (SelectedDate.HasValue && selectedDate.HasValue && SelectedDate.Value == selectedDate.Value) { ChangeSelectedDate(selectedDate); //removed to avoid deselection //SelectedDate = null; } else { SelectedDate = selectedDate; } }