4 Answers, 1 is accepted
Hello,
You could subscribe to the AppointmentsSource CollectionChanged event and it its handler track when a new appointment is added or an existing appointment is deleted. Here is a quick example:
(calendar.AppointmentsSource as ObservableCollection<Appointment>).CollectionChanged += (sender, e) =>
{
if(e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
var newApp = e.NewItems[0] as Appointment;
}
};
As to an existing appointments changes - you would need to subscribe to PropertyChanged event of each appointment to track for updates:
foreach(var appt in (calendar.AppointmentsSource as ObservableCollection<Appointment>))
{
appt.PropertyChanged += (sender, e) =>
{
var updatedApp = sender as Appointment;
};
}
I agree that providing ready-to-use events for appointments updates will be quite helpful, so I logged a feature request on your behalf regarding this functionality. You can cast your vote and track its status at the link below:
https://feedback.telerik.com/xamarin/1435845-calendar-add-events-for-appointments-changes
Let me know if I can help with anything else.
Regards,
Yana
Progress Telerik
Hi Yana,
I tried to use these codes, but I get a System.NullReferenceException by
"(calendar.AppointmentsSource as ObservableCollection<Appointment>)"
What do I have to do, else?
Hi Kaan,
One possible reason for the error is if you try to get the Calendar AppointmentsSource too early - in order to ensure that the AppointmentsSource is available, you can use the PropertyChanged event of the Calendar like this:
<telerikInput:RadCalendar x:Name="calendar"
PropertyChanged="calendar_PropertyChanged"
.... />
And the event handler:
private void calendar_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(RadCalendar.AppointmentsSource))
{
if((sender as RadCalendar).AppointmentsSource != null)
{
// subscribe to CollectionChanged here
}
}
}
Also please check the AppointmentsSource is valid and of the same type.
Give it a try and let me know how it goes.
Regards,
Yana
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
I was able to solve it myself. It was because I did not check if the list of appointments is greater than 0.
But thank you for the fast support. The Support of telerik is great.
Best regards,
Kaan Congar