XamForms.Controls.Calendar
XamForms.Controls.Calendar copied to clipboard
Jump to Month of Selected Date
Hi @rebeccaXam ,
I want calendar view to jump to the date selected from datepicker.
I have tried Calendar.ForceRedraw()
but it's not working. I also tried Calendar.SelectedDates.Add()
and that doesn't work too.
Please suggest a way to redraw the calendar and jump to month of selected date.
- Prakash
changing the date using the picker is easy
in XMAL:
<DatePicker Grid.Row="2" DateSelected="Handle_DateSelected"> <DatePicker.Format>dd-MM-yyyy</DatePicker.Format> </DatePicker>
In CodeBehind:
void Handle_DateSelected(object sender, Xamarin.Forms.DateChangedEventArgs e) { calendar.SelectedDate = e.NewDate; }
The issue is that, if I change the date to a different month than the one currently showing, it will be selected but it will not move to that month.
@ali-h2010 yes exactly...
Po-ta-to
Poh-tah-toh
I think that you need to just change the StartDate and set it to whatever new value is selected from the picker. In XamForms.Controls.Calendar/XamForms.Controls.Calendar/Calendar.MonthNavigation.cs when the user click on the right or left arrow, a new date is created and the day is set to 1 of that new month. `protected void RightArrowClickedEvent(object s, EventArgs a) { if (CalendarViewType == DateTypeEnum.Year) { NextPrevYears(true); } else { NextMonth(); } RightArrowClicked?.Invoke(s, new DateTimeEventArgs { DateTime = StartDate }); RightArrowCommand?.Execute(StartDate); }
public void NextMonth()
{
StartDate = new DateTime(StartDate.Year, StartDate.Month, 1).AddMonths(ShowNumOfMonths);
}`
Hi @ali-h2010
That worked like a charm....
The only issue now is that it doesn't show the selected date somehow. Please suggest any workaround for that...
Thank you in advance Prakash
@prakashsatyani , I am not sure if this is sarcasm or not. I will try to test myself and see what is the issue.
I am not actually one of the contributors of this repository but I really liked this free awesome component and want to support it in the future.
Hi @ali-h2010 ,
That was not a sarcasm. I really am facing this issue.
I am setting StartDate
and SelectedDate
both as the date selected from datepicker.
The month changes as per your suggestion but the date selection does not show.
I love that you cared to reply and appreciate it...