How to Snap to Grid on Week View

Hi all!

I'm very new to the syncfusion WPF controls but am really interested in the Scheduler. I've had a play around with it in a test application, but one feature I'd really like that I can't find is "snap to grid" for the week view. I've set my time intervals to 5 minutes and have set the "minimum appointment duration" to 5 minutes, but I also want to limit a user to creating appointments at those 5 minute intervals.

I realise that I can enforce this via my ViewModel - I can simply round a time up or down to 5 minutes. However, I'd really like the drag and drop animations to snap directly to my time intervals.

Is there a way to achieve this?

Cheers,

Adam


2 Replies

PO PopeGregoryIX April 25, 2022 02:48 AM UTC

To partly reply to my own question:


public DateTime From

        {

            get => Appointment.From;

            set

            {

                int mins = value.Minute % 5;

                if(mins != 0) mins = (5 - (mins % 5));

                Appointment.From = value + TimeSpan.FromMinutes(mins);

            }

        }


This solution *does* provide snapping after you let go of the rescheduled appointment, but doesn't snap the visuals *during*



SS SaiGanesh Sakthivel Syncfusion Team April 25, 2022 02:59 PM UTC

Hi Adam,


#Regarding Drag and Drop the appointment

Your requirement can be achieved with the help of AppointmentDropping Event in the SfScheduler. Please refer to the following code snippet for your reference.


Code snippet

private void Schedule_AppointmentDropping(object sender, AppointmentDroppingEventArgs e)

{

    int mins = e.DropTime.Minute % 5;

    if (mins != 0)

        mins = (5 - (mins % 5));

    e.DropTime = e.DropTime + TimeSpan.FromMinutes(mins);

}


Please refer to the tested sample in the following locations.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SchedulerWPF83919731


Please let us know if you have any concerns.


Regards,
SaiGanesh Sakthivel


Loader.
Up arrow icon