andrea,
I'm struggling through getting sfSchedule to work with WPF too. Here's what I'm doing to detect changes in the appointment collection, and it's been working for me.
I don't know, yet, how to post code properly on this forum, so if you want you can check out my gist on github:
https://gist.github.com/scottpage/5b842e54fe19c1beb683d09050c654a5
I'll post my entire class to help you, here's the link:
https://gist.github.com/scottpage/4af0b9a269c4fed42784ec3795bc1748
I hope this helps, if not, let me know and I'll be more than happy to help you out. I've struggled enough with sfSchedule and MVVM, I'd hate to see anyone else do the same.
Some info to help you understand my code without seeing outside of this method:
1) ScheduledEventAppointment is an abstract (MustInherit) class that inherits from ScheduleAppointment (provided by Syncfusion sfSchedule).
2) My.Application.Api is a property of a custom class, in Application.xaml.vb, that I created for my REST api server. Keep in mind, it's just a class with functions that return an object.
3) I'm breaking MVVM rules by using MessageBox.Show for testing only. I haven't implemented any kind of dependency injection, yet.
4) SESA.IsExamination is an extension method for ScheduledEventAppointment that determines the derived (inherited) Type of the current ScheduledEventAppointment.
5) AddScheduledEventScheduledAppointment is a method used to add the appointment to the schedule.
Private Async Sub ScheduledEvents_CollectionChanged(sender As Object, e As NotifyCollectionChangedEventArgs)
Select Case e.Action
Case NotifyCollectionChangedAction.Remove
If _DeletingEventFromOtherLocation Then Return
Dim SESA = DirectCast(e.OldItems(0), ScheduledEventAppointment)
If MessageBox.Show(String.Format("Arg you sure you want to delete scheduled event {0}", SESA.ScheduledEvent.Id), "Deleting Event", MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
Await My.Application.Api.DeleteExaminationEventAsync(SESA.ScheduledEvent.Id)
Else
If SESA.IsExamination Then
AddScheduledEventScheduledAppointment(SESA.AsExamination.Examination)
End If
End If
End Select
End Sub
'*** REST API (Calls to server) ***
Public Async Function DeleteExaminationEventAsync(id As Integer) As Task(Of Integer)
Dim Request As New RestRequest(String.Format("/Examinations/{0}", id), Method.DELETE)
Dim Response = Await _Client.ExecuteTaskAsync(Of Integer)(Request)
Return Response.Data
End Function
'*** METHODS IN SAME CLASS AS CollectionChanged EVENT ***
Private Sub AddScheduledEventScheduledAppointment(newEvent As ExaminationInfoDto)
If My.Application.Dispatcher.CheckAccess Then
If ScheduledEvents.ContainsExamination(newEvent.Id) Then Return
Dim ESA As New ExaminationAppointment(newEvent, ExaminationStatus)
_AddingEventFromMainHub = True
ScheduledEvents.Add(ESA)
_AddingEventFromMainHub = False
Else
My.Application.Dispatcher.BeginInvoke(New Action(Of ExaminationInfoDto)(AddressOf AddScheduledEventScheduledAppointment), (newEvent))
End If
End Sub
' *** EXTENSIONS ***
<Extension>
Public Function IsExamination(sa As ScheduledEventAppointment) As Boolean
Return TypeOf sa Is ExaminationAppointment
End Function