This is a migrated thread and some comments may be shown as answers.

OnAppointmentChanged or OnAppointmentAdded

4 Answers 47 Views
Calendar & Scheduling
This is a migrated thread and some comments may be shown as answers.
x
Top achievements
Rank 1
x asked on 22 Oct 2019, 12:38 PM

I need an OnAppointmentChanged or OnAppointmentAdded event to be able to save the change or the new appointment.

I could not find such events. How to achieve this goal?

4 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 24 Oct 2019, 09:10 AM

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

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Kaan
Top achievements
Rank 1
answered on 13 Jan 2021, 10:47 AM

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?

0
Yana
Telerik team
answered on 13 Jan 2021, 03:35 PM

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

0
Kaan
Top achievements
Rank 1
answered on 14 Jan 2021, 08:49 AM

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

Tags
Calendar & Scheduling
Asked by
x
Top achievements
Rank 1
Answers by
Yana
Telerik team
Kaan
Top achievements
Rank 1
Share this question
or