XamForms.Controls.Calendar icon indicating copy to clipboard operation
XamForms.Controls.Calendar copied to clipboard

Jump to Month of Selected Date

Open prakashsatyani opened this issue 6 years ago • 6 comments

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

prakashsatyani avatar Jul 11 '18 10:07 prakashsatyani

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 avatar Jul 11 '18 11:07 ali-h2010

@ali-h2010 yes exactly...

Po-ta-to Poh-tah-toh

prakashsatyani avatar Jul 11 '18 12:07 prakashsatyani

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);
	}`

ali-h2010 avatar Jul 12 '18 05:07 ali-h2010

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 avatar Jul 12 '18 06:07 prakashsatyani

@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.

ali-h2010 avatar Jul 12 '18 12:07 ali-h2010

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...

prakashsatyani avatar Jul 12 '18 12:07 prakashsatyani