Hi,
I am using the Calendar component and I try just simply to have a calendar in which I can select a init and end dates.
The SelectionMode = SelectionMode.MultiSelection, does not suit since you can select more than two dates.
So I am using SelectionMode = SelectionMode.RangeSelection. I am trying this on iOS for the moment. Basically I can only select the dates within the month, and if I press another month the selection goes away. Moreover, the application closes (I think it crashes but I do not see any exceptions logged), when you press and maintain a day and you put your finger over the arrows of going to the previous or next month.
How can I achieve my requirement of selecting Init and End Date with this component within months or even years?
I need this to be solved as soon as possible since I need to deliver to my clients.
Thank you very much,
PD: The code is just:
public class CalendarView : BaseContentPage
{
public event EventHandler AcceptClicked;
SfCalendar calendar;
DateTime _startDate, _endDate;
public CalendarView(DateTime startDate, DateTime endDate)
{
ToolbarItems.Add(new ToolbarItem(AppResources.OK, "", AcceptButton));
ToolbarItems.Add(new ToolbarItem(AppResources.Cancel, "", CancelButton));
this._startDate = startDate;
this._endDate = startDate;
Content = GetLayout();
}
private void AcceptButton(object sender, EventArgs e)
{
AcceptButton();
}
private void CancelButton(object sender, EventArgs e)
{
CancelButton();
}
private async void AcceptButton()
{
DateFilterEventArgs args = new DateFilterEventArgs();
try
{
DateTime startDate = calendar.SelectedDates[0];
DateTime endDate = calendar.SelectedDates[1];
bool fechaIncorrecta = (startDate.Date > endDate.Date);
args.startDate = fechaIncorrecta ? _startDate : startDate.Date;//do not change the dates if the user puts wrong dates
args.endDate = fechaIncorrecta ? _endDate : endDate.Date;
AcceptClicked(null, args);
await Navigation.PopModalAsync();
}
catch (Exception ex)
{
((ViewModels.CalendarVM)this.BindingContext).DialogService.ShowError("SELECCIONAR DOS FECHAS");
}
}
private async void CancelButton()
{
await Navigation.PopModalAsync();
}
private View GetLayout()
{
return calendar = new SfCalendar()
{
MaxDate = DatesHelper.GetDateTimeNow(),
SelectionMode = SelectionMode.RangeSelection,
};
}
}
}