How do I change which timespan the day view is showing when it is opened?
I would like it to scroll to the current time when opened, instead of staying at the minimum time for that day.
Also, has anyone implemented a line showing the current time?
9 Answers, 1 is accepted
With the current implementation of the Xamarin.Forms Calendar, the desired functionalities are not supported out of the box. We have a feature request logged for controlling the first time slot shown - Calendar: Add functionality to scroll to the first available event when in mode. I have increased its priority as per your request. Please follow the item in order to subscribe for automatic notifications.
In the meantime, you can partially achieve the desired behavior by creating custom renderers and utilizing the native controls. For example, in iOS:
[assembly: ExportRenderer(
typeof
(RadCalendar),
typeof
(DayViewCalendarRenderer))]
namespace
TelerikXamarin.iOS
{
public
class
DayViewCalendarRenderer : CalendarRenderer
{
public
override
bool
TrySetViewMode(Telerik.XamarinForms.Input.CalendarViewMode view,
bool
isAnimated)
{
bool
hasNavigated =
base
.TrySetViewMode(view, isAnimated);
var presenter = Control?.Presenter
as
TKCalendarDayViewPresenter;
if
(presenter !=
null
)
{
presenter.DayView.EventsView.Interval = Convert.ToDouble(3600 * 0.25);
presenter.DayView.EventsView.StartTime = 3600 * 8;
presenter.DayView.EventsView.EndTime = 3600 * 22;
presenter.DayView.EventsView.Style.LabelFormatter =
new
NSDateFormatter { DateFormat =
"hh:mm"
};
presenter.DayView.EventsView.UpdateLayout();
}
return
hasNavigated;
}
}
}
I have attached a sample for your reference.
Regards,
Stefan Nenchev
Progress Telerik
Hello Stefan, thanks for the reply.
Your suggestion solves how many hours is visible, thank you for that.
What I am more interested in is how to scroll to the current time when the calendar is opened.
Even better would be an option to show a line with the current time as well.
Is this possible?
Unfortunately, these functionalities are not available. I have added your requirement to the feature request so we can consider implementing them as well.
Regards,
Stefan Nenchev
Progress Telerik
Indeed, it seems more intuitive to set the starting time to a more convenient time in the morning considering the business hours. We have logged the task at our end and will consider implementing it at some point. Here is the public item which you can track - Calendar: Change default time period. I have added some points to your account for the suggestion. You can follow the item in order to subscribe for automatic notifications.
Regards,
Stefan Nenchev
Progress Telerik
Hi Guys,
Another year has past. Is there any way to get the iOS Calendar in Xamarin.Forms to scroll to an appointment or at least to DateTime.Now ?
Workaround:
When the view changes, find the earliest appointment, then set the Calendar's DayStartTime to an hour or so before that appointment This will make it look like the calendar scrolled and since there are no earlier appointments, nothing is hidden:
if (firstAppointmentOfTheDay != null)
{
Calendar.DayViewSettings.DayStartTime = new TimeSpan(0, firstAppointmentOfTheDay.StartDate.AddHours(-2).Hour, 0, 0);
}
else
{
//If there are no items for the day, then just show 6am
Calendar.DayViewSettings.DayStartTime = new TimeSpan(0, 6, 0, 0);
}
Yeah, that works great. Until the user slides to the next day (or more) and the calendar jumps up and down depending on where the appointments are. Or until you come to a day with the first appointment at 3PM and you want to add an appointment at 10AM.
Seriously, I can't belive this is not implemented yet.
I agree scrolling the view to a specific appointment / time is important functionality and we will definitely look into ways to implement it soon.
I am sorry for the caused inconvenience due to the missing feature in RadCalendar control.
Regards,
Yana
Progress Telerik