0

I have a class Activity that inherit from RealmObject. I am adding it to the realm database and there's a the page that contains a weekly SfSchedule. When the user choose an appointment(all the appointment are retrieved from the database using realm) an action sheet pops up and there is an option delete.

  private async void Details_CellTapped(object sender, ScheduleTappedEventArgs args) {
     var action = await DisplayActionSheet("More details", "Cancel",null, "Details","Update", "Delete");
     if (action == "Delete") {
        realm = Realm.GetInstance();
        var activityItem = (Activity)args.selectedAppointment;
        realm.Write(() => realm.Remove(activityItem));
     }
  }

It give me an error System.InvalidCastException: Specified cast is not valid.

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
Mireille
  • 637
  • 2
  • 12
  • 27
  • DataSource property of Schedule control is of type IEnumerable, so it allows you to perform CRUD operation with AppointmentMapping feature in it. Since you are mentioning about casting exception, could you check with updating the objects with proper boxing (if needed). or else check the same scenario with list view in its selection changed method. That will helps to ensure the issue with the schedule control. – Joy Rex Sep 27 '16 at 07:06
  • check the data type of "args.selectedAppointment" while "Details_CellTapped" event triggered. – Joy Rex Sep 27 '16 at 08:54
  • The type of args.selectedAppointment is a object I have to convert it to RealmObject – Mireille Sep 27 '16 at 13:58

1 Answers1

0

Please check if that InvalidCastException is occurring on the line

var activityItem = (Activity)args.selectedAppointment;

it looks like this is nothing to do with Realm.

Andy Dent
  • 17,578
  • 6
  • 88
  • 115