Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump to Month of Selected Date #84

Open
prakashsatyani opened this issue Jul 11, 2018 · 6 comments
Open

Jump to Month of Selected Date #84

prakashsatyani opened this issue Jul 11, 2018 · 6 comments

Comments

@prakashsatyani
Copy link

prakashsatyani commented Jul 11, 2018

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
@ali-h2010
Copy link

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.

@prakashsatyani
Copy link
Author

@ali-h2010 yes exactly...

Po-ta-to Poh-tah-toh

@prakashsatyani prakashsatyani changed the title Jump to Selected Date/Month Jump to Month of Selected Date Jul 11, 2018
@ali-h2010
Copy link

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

@prakashsatyani
Copy link
Author

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

@ali-h2010
Copy link

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

@prakashsatyani
Copy link
Author

prakashsatyani commented Jul 12, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants