We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Set Dragging Time

Hello,

   I am trying to set the SFSchedule in my Xamarin.Forms app to be able to drag and drop an appointment.  The drag and drop feature works, however, it moves the appointment in 1 minute increments, I would like to set the increment to 15 minutes however in the AppointmentDragOver event the arg e.DraggingTime is read only.  Any help you can provide would be appreciated.

3 Replies

SP Subburaj Pandian Veluchamy Syncfusion Team May 31, 2019 01:33 PM UTC

Hi MikeD, 
 
Thank you for contacting Syncfusion support. 
 
Based on provided information your requirement of “increasing the appointment dragging time to 15mins in AppointmentDragOver method” can be achieved in sample level by enabling ShowTimeIndicatorproperty schedule in AppointmentDragOver method. InAppointmentDrop method we have set the StartTime and EndTime value based on the drop time of the appointment. We have prepared the simple sample for the same. 
 
Code Snippet: 
      schedule.AppointmentDragOver += Schedule_AppointmentDragOver; 
        private void Schedule_AppointmentDragOver(object sender, AppointmentDragEventArgs e) 
        { 
            schedule.DragDropSettings.ShowTimeIndicator = ((e.DraggingTime.Minute % 15) == 0); 
        } 
  
 
 schedule.AppointmentDrop += SfSchedule_AppointmentDrop; 
 private void SfSchedule_AppointmentDrop(object sender, AppointmentDropEventArgs e) 
        { 
            var time = e.DropTime; 
            var remainder = time.Minute % 15; 
            var appointment = e.Appointment as ScheduleAppointment; 
            var appointmentDuration = appointment.EndTime - appointment.StartTime; 
  
            if (remainder != 0) 
            { 
                e.DropTime = (remainder < 7) ? time.AddMinutes(-remainder) : time.AddMinutes(15 - remainder); 
                appointment.StartTime = e.DropTime; 
                appointment.EndTime = e.DropTime.AddHours(appointmentDuration.Hours); 
            } 
        } 
  
We have attached sample for your reference, 
 
 
Kindly, refer the following User Guide documentation link reading the same, 
 
 
We hope this helps. Please let us know if you need any further assistance. 
 
Regards,  
Subburaj Pandian V  



MI MikeD May 31, 2019 09:18 PM UTC

Thank you, that did it! I modified your code a little to better suit my logic.

        void Schedule_AppointmentDragOver(object sender, AppointmentDragEventArgs e)
        {
                                                          //We are limiting the appointments to increments of 15 minutes for the drag and drop so TimeIndicator only shows 00, 15, 30, 45
            Schedule.DragDropSettings.ShowTimeIndicator = ((e.DraggingTime.Minute % 15) == 0);
        }

        void Schedule_AppointmentDrop(object sender, AppointmentDropEventArgs e)
        {
            ScheduleAppointment appointment = e.Appoin
tment as ScheduleAppointment;
                              //Get the index of the modified appoint in the collection
            int ind = collection.IndexOf(appointment);                
                              //We are limiting the appointments to increments of 15 minutes for the drag and drop
                             int newTime = Convert.ToInt16(Math.Floor(e.DropTime.Minute / 15.0) * 15.0);
            TimeSpan appointmentDuration = appointment.EndTime - appointment.StartTime;
                              //subtract current start time from current start time which makes zero then add newTime (minutes)
            appointment.StartTime = appointment.StartTime.AddMinutes(-appointment.StartTime.Minute + newTime);
            appointment.EndTime = appointment.StartTime + appointmentDuration;
                             //update the collection            
                             collection[ind] = appointment;
        }
 
 


SP Subburaj Pandian Veluchamy Syncfusion Team June 3, 2019 07:01 AM UTC

Hi Michael,

Thank you for the update. We are glad that the given solution meets your requirement. 
 
Please get in touch with us if you would require any further assistance. 
 
Regards,
Subburaj Pandian V 


Loader.
Live Chat Icon For mobile
Up arrow icon