Thanks for your extremely fast response and the sample code which works and has helped me diagnose one problem in my code - on Android, the OnVisibleDatesChanged event is after all the OnMonthCellLoadedEvent calls. This means I cannot load data in OnVisibleDatesChanged. On iOS, the OnVisibleDatesChanged event occurs first.
I have years of experience with using event-driven frameworks so I should know to not expect events to necessarily be in the same order across platforms, so this is a little embarrassing for me.
Something else that is now happening has me completely baffled - I am getting different values in the debug log compared to what is drawn on the screen, for Android.
I changed the month cell logic a little as shown below, so it would show the day/month in the cells. That works fine and the cells drawn show the expected values. However, the values dumped to the debug log are a month later. I know how stupid that sounds but I have tested it five times now, deleting from the device each time. I suspect this is a Xamarin problem but am extremely confused. I'm not asking for your help with this, unless it is something you know about, as the visible behaviour of the control is what I want. I am mainly writing it up here in case someone else has similar insane behaviour and gets lost debugging it.
void Schedule_OnMonthCellLoadedEvent(object sender, MonthCellLoadedEventArgs e)
{
var dayStr = $"{e.date.Day}/{e.date.Month}";
Debug.WriteLine(dayStr);
var monthCell = new StackLayout { BackgroundColor = Color.Transparent };
var monthLabel = new Label();
monthLabel.HeightRequest = 50;
monthLabel.WidthRequest = 50;
monthLabel.Margin = new Thickness(0, 0, 10, 10);
monthLabel.BackgroundColor = Color.Green;
monthLabel.Text = dayStr;
monthLabel.TextColor = Color.White;
monthCell.Children.Add(monthLabel);
e.view = monthCell;
}
void Schedule_OnVisibleDatesChanged(object sender, VisibleDatesChangedEventArgs e)
{
var firstDay = e.visibleDates[0];
var lastDay = e.visibleDates[e.visibleDates.Count - 1];
Debug.WriteLine($"Dates Changed: {firstDay.Day}/{firstDay.Month} to {lastDay.Day}/{lastDay.Month}");
}
AFTER A SWIPE
The device shows January 2018, as expected with a visible range drawn of 31/12 to 10/2
The debug log shows: (Andy note - this list of strings is a month later than that displayed using the same string.)
28/1
29/1
... deleted consecutive log lines to save space here
10/3
Dates Changed: 31/12 to 10/2
(Andy note - the range in the "Dates Changed" event match the dates shown in the VISIBLE display)