Resize spot precision

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

    Posted 17 Jan 2014 Link to this post

    Hi,

    I'm using a WeekViewDefinition and I would like to know when I resize a spot if it's possible to resize more than 1 min at a time???

    Thank's
    Alain
  2. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 22 Jan 2014 Link to this post

    Hi Alain,

    The desired scenario can be achieved by setting the SnapAppointments property of the ScheduleView to True. By default this will snap by the MinorTickLength of the current ViewDefition. You can also implement a custom SnapBehavior which will allow you to snap by a specific time not related to the used MinorTickLength. For more details please check the following article from our online help documentation:
    http://www.telerik.com/help/wpf/radscheduleview-features-snapappointments.html

    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 22 Jan 2014 Link to this post

    Thank's Kalin :)

    The "SnapAppointment" do exactly what I need for the drag'n drop but for a resize operation I need to keep the "SnapAppointment=False" behaviour, is this possible?!?

    Alain
  5. Answer
    Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 24 Jan 2014 Link to this post

    Hi Alain,

    You will be able to achieve the desired by implementing a custom ScheduleView DragDropBehavior. Afterwards you will need to override the CanStartResize and Resize methods the following way:

    public override bool CanStartResize(DragDropState state)
    {
        var scheduleView = state.ServiceProvider.GetService<IDialogProvider>() as RadScheduleView;
        scheduleView.SnapAppointments = false;
        return base.CanResize(state);
    }
     
    public override void Resize(DragDropState state)
    {
        var scheduleView = state.ServiceProvider.GetService<IDialogProvider>() as RadScheduleView;
        scheduleView.SnapAppointments = true;
        base.Resize(state);
    }

    This when the resize operation is starting the SnapAppointments property of the ScheduleView will be set on false and when the resize is finished the property is set back on true.

    Hope this will work for you.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 06 Feb 2014 in reply to Kalin Link to this post

    Hi Kalin,

    my needs change a little bit :) No matter what is the value of the MinorTickLength, the drag 'n' drop should always snap by 5 mins but the resize new to be by x mins, x is an int value in my appointment object.

    Thank's
    Alain
  7. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 06 Feb 2014 Link to this post

    Kalin,

    I found my solution, thank you in advance :)

    Alain
  8. Christie Admin
    Christie Admin avatar
    239 posts
    Member since:
    Aug 2013

    Posted 26 Feb 2014 in reply to Kalin Link to this post

    Hi Kalin,

    regarding the following link: http://www.telerik.com/help/wpf/radscheduleview-features-snapappointments.html
    I think there is an issue with the piece of code....

    If you have a period which start at 12:05 and finish at 12:38 and you need to resize the end by 11 mins, the first resize step increase the ending of the period by 5 mins then the next one will be ok....

    Thank's
    Alain

       public class CreateScheduleCustomSnapBehavior : SnapBehavior
        {        
            #region Protected methods.
            protected override System.Windows.Freezable CreateInstanceCore()
            {
                return null;
            }
            #endregion

            #region Public methods.
            public override DateTime SnapEnd(SnapData pSnapData, DateTime pTimeToSnap)
            {
                RadScheduleView scheduleView = pSnapData.ServiceProvider.GetService<IDialogProvider>() as RadScheduleView;
                CreateScheduleSpot theSpot = pSnapData.OriginalData as CreateScheduleSpot;
                int minutes = scheduleView.SnapAppointments ? 5 : Convert.ToInt32(theSpot.SpotsDuration.TotalMinutes);

                // We don't need a divide by zero exception in the "SnapToTimeSpan" method!!!
                if (minutes == 0)
                {
                    minutes = 15;
                }

                if (pTimeToSnap >= pSnapData.OriginalData.End)
                {
                    return SnapToTimeSpan(TimeSpan.FromMinutes(minutes), pTimeToSnap, true);                
                }
                else
                {
                    return SnapToTimeSpan(TimeSpan.FromMinutes(minutes), pTimeToSnap, false);
                }
            }

            public override DateTime SnapStart(SnapData pSnapData, DateTime pTimeToSnap)
            {
                RadScheduleView scheduleView = pSnapData.ServiceProvider.GetService<IDialogProvider>() as RadScheduleView;
                CreateScheduleSpot theSpot = pSnapData.OriginalData as CreateScheduleSpot;
                int minutes = scheduleView.SnapAppointments ? 5 : Convert.ToInt32(theSpot.SpotsDuration.TotalMinutes);

                // We don't need a divide by zero exception in the "SnapToTimeSpan" method!!!
                if (minutes == 0)
                {
                    minutes = 15;
                }

                if (pTimeToSnap >= pSnapData.OriginalData.End)
                {
                    return SnapToTimeSpan(TimeSpan.FromMinutes(minutes), pTimeToSnap, true);
                }
                else
                {
                    return SnapToTimeSpan(TimeSpan.FromMinutes(minutes), pTimeToSnap, false);
                }
            }

            public static DateTime SnapToTimeSpan(TimeSpan pTimeSpan, DateTime pTimeToSnap, bool pRoundToBiggestNumber)
            {
                var difference = pTimeToSnap.Ticks % pTimeSpan.Ticks;

                if (pRoundToBiggestNumber)
                {
                    return pTimeToSnap.AddTicks(pTimeSpan.Ticks - difference);
                }

                return pTimeToSnap.AddTicks(-difference);
            }
            #endregion
        }


  9. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 04 Mar 2014 Link to this post

    Hi Alain,

    I tested the code from the article and didn't observe any issues there. However you won't be able to resize the Appointment with 11 minutes as the snap behavior is set to 5 minutes and it is also rounding the time. Please share some more details on what you need to achieve so we can help you further.

    I'm looking forward to hearing from you.

    Regards,
    Kalin
    Telerik
Back to Top
UI for WPF is Visual Studio 2017 Ready