Drag and drop out of bound

5 posts, 0 answers
  1. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 18 Feb 2015 Link to this post

    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
  2. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 19 Feb 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 23 Feb 2015 Link to this post

    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.

     
  5. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 23 Feb 2015 in reply to Kalin Link to this post

    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
  6. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 26 Feb 2015 Link to this post

    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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready