This question is locked. New answers and comments are not allowed.
Hi,
I use timeline view with resource grouping and snap appointments (see attached image).
The appointments fill up a whole day.
The appointments can be dragged between different days for the same resource or even between different resources.
I need to detect on drop, if I drop the appointment on a slot that alredy contains an appointment or if it is empty.
How can I do that?
I have a custom DragDropBehavior that looks like this:
In this code I can find out if I dropped the appointment on another resource (Employee) and change it's ID.
But I also need to find out if the destination slot already contained an appointment before the drop.
Regards,
HÃ¥kan
I use timeline view with resource grouping and snap appointments (see attached image).
The appointments fill up a whole day.
The appointments can be dragged between different days for the same resource or even between different resources.
I need to detect on drop, if I drop the appointment on a slot that alredy contains an appointment or if it is empty.
How can I do that?
I have a custom DragDropBehavior that looks like this:
public class CustomDragDropBehavior : ScheduleViewDragDropBehavior { public event EventHandler<EventArgs<TimeScheduleShift>> NewShiftDropped; public override void Drop(DragDropState state) { if (state.IsControlPressed) { // TODO: Copy shift } if (state.SourceAppointmentsSource == state.DestinationAppointmentsSource) { if (state.Appointment != null && state.DestinationSlots.Count() > 0) { // Get dragged shift TimeScheduleShift shift = state.Appointment as TimeScheduleShift; if (shift != null) { // Get destionation slot (where shift is dropped) DragDropSlot slot = state.DestinationSlots.First() as DragDropSlot; if (slot != null && slot.Resources.Count() > 0) { // Get destination slot's employee TimeScheduleEmployeeResource employee = slot.Resources.First() as TimeScheduleEmployeeResource; if (employee != null) { // Check if destination employee is different from source employee int employeeId = 0; Int32.TryParse(employee.ResourceName, out employeeId); if (employeeId != 0 && employeeId != shift.EmployeeId) shift.EmployeeId = employeeId; } } } } base.Drop(state); } else { // Get dropped shift var newShift = state.Appointment as TimeScheduleShift; // Get time slot where shift was dropped Slot droppedAtSlot = state.DestinationSlots.First(); // Calculate offset between default shift start and actual dropped at start TimeSpan offset = droppedAtSlot.Start - newShift.Start; // Set new times based on dropped time newShift.Start = newShift.Start.Add(offset); if (newShift.BreakStart.HasValue) newShift.BreakStart = newShift.BreakStart.Value.Add(offset); if (newShift.BreakStop.HasValue) newShift.BreakStop = newShift.BreakStop.Value.Add(offset); newShift.End = newShift.End.Add(offset); newShift.ActualStart = newShift.Start; newShift.ActualEnd = newShift.End; // Add shift to collection (state.DestinationAppointmentsSource as ObservableCollection<TimeScheduleShift>).Add(newShift); if (NewShiftDropped != null) NewShiftDropped(this, new EventArgs<TimeScheduleShift>(newShift)); } } }In this code I can find out if I dropped the appointment on another resource (Employee) and change it's ID.
But I also need to find out if the destination slot already contained an appointment before the drop.
Regards,
HÃ¥kan