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

Drag and drop out of bound

4 Answers 101 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Christie Admin
Top achievements
Rank 1
Christie Admin asked on 18 Feb 2015, 07:53 PM
Hi,

I would like to know if it's possible to block the drag and drop operation outside the DayStartTime/DayEndTime properties?!? In my scenario, I have a week view with the DayStartTime property = 9h00AM and the DayEndTime property = 9h00PM and an appointment from 9h00AM to 9h00PM. If I want to drag the appointment to another day, it's a little bit hard to don't fall outside the DayStartTime/DayEndTime properties range. If I fall outside the range, I don't want the appointment become resizable, is it possible???

Thank's
Alain

4 Answers, 1 is accepted

Sort by
0
Christie Admin
Top achievements
Rank 1
answered on 20 Feb 2015, 02:13 AM
Addition infos regarding my post...

what I need it's when I try to drag before the DayStartTime or after the DayEndTime, I would like the visible dragged item to stop. With this behavior, if I have an appointement which cover all the space between the DayStartTime and the DayEndTime and I want the drag it on an anotehr day it will be much easier.

Thank's
Alain
0
Kalin
Telerik team
answered on 23 Feb 2015, 08:41 AM
Hi Alain,

Thank you for contacting us.

What I can suggest you would be to try to achieve the desired using a custom ScheduleViewDragDropBehavior. By overriding the CanDrop method and returning false you can prevent the drop if the Start time of the first Slot in the state.DestinationSlots moves to the previous day for example.

Hope this will help you to achieve the required.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Christie Admin
Top achievements
Rank 1
answered on 23 Feb 2015, 05:11 PM
Hi Kalin,

the only problem I have it's when I have an appointment that occupied a full day and I want to drag it on another day, it's verry hard to don't fall "out of bounds"!!! Actually I already have a CustomDragDropBehavior and I check if the first destination slot fall before the DayStartTime.

I'm looking for a logic which considering the fact that the user doesn't have the ability to be so precise. I'm looking for something when the user drag operation fall before the DayStartTime or after the DayEndTime, I can let him continue dragging but when he release his drag operation, I can adjust the destinations slots to match the DayStartTime/DayEndTime.

Thanks,
Alain
0
Kalin
Telerik team
answered on 26 Feb 2015, 12:52 PM
Hi Alain,

You will be able to achieve the desired by using a custom SnapBehavior. You can for example set the IsAllDayEvent property of the Appointment to true and implement the following SnapBehavior:

public class CustomSnapBehavior : SnapBehavior
{
    public override DateTime SnapEnd(SnapData snapData, DateTime timeToSnap)
    {
        var app = snapData.OriginalData as Appointment;
        var durationToAdd = timeToSnap.Date - snapData.OriginalData.End.Date;
 
        if (app.IsAllDayEvent)
        {
            return snapData.OriginalData.End.AddDays(durationToAdd.Days);
        }
        else
        {
            return SnapToTimeSpan(TimeSpan.FromMinutes(1), timeToSnap, false);
        }
             
    }
 
    public override DateTime SnapStart(SnapData snapData, DateTime timeToSnap)
    {
        var app = snapData.OriginalData as Appointment;
        var durationToAdd = timeToSnap.Date - snapData.OriginalData.Start.Date;
 
        if (app.IsAllDayEvent)
        {
            return snapData.OriginalData.Start.AddDays(durationToAdd.Days);
        }
        else
        {
            return SnapToTimeSpan(TimeSpan.FromMinutes(1), timeToSnap, false);
        }
    }
 
    public static DateTime SnapToTimeSpan(TimeSpan timeSpan, DateTime timeToSnap, bool roundToBiggestNumber)
    {
        var difference = timeToSnap.Ticks % timeSpan.Ticks;
        if (roundToBiggestNumber)
        {
            return timeToSnap.AddTicks(timeSpan.Ticks - difference);
        }
 
        return timeToSnap.AddTicks(-difference);
    }
 
    protected override System.Windows.Freezable CreateInstanceCore()
    {
        return new CustomSnapBehavior();
    }
}

Hope this helps.

Regards,
Kalin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
ScheduleView
Asked by
Christie Admin
Top achievements
Rank 1
Answers by
Christie Admin
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or