/// <summary> /// Updates cell highlights and resize handle visual position /// </summary> /// <param name="sender">Resize handle dragger</param> /// <param name="args">Drag event args</param> private void HandleResizeDragging(object sender, DragEventArgs args) { var dragger = sender as DraggableView; if (dragger == null) { return; } // Actually, this time we don't care about the center so much as the edge.... but the difference isn't too noticeable var destinationPoint = dragger.ParentView.TranslatePointToAncestor(args.Center, _grid); var newDate = GetDateAtPoint(destinationPoint); if (newDate == null) { return; } // We re-set newDate after applying it to the resize range because TimeRange // may have adjusted it to preserve a valid time range // if (dragger == _rightResizeHandleDragger) { _resizeRange.EndDate = newDate.Value; newDate = _resizeRange.EndDate; } else { _resizeRange.StartDate = newDate.Value; newDate = _resizeRange.StartDate; } // Highlight new date range // HighlightCells(_resizeRange.StartDate, _resizeRange.EndDate); // Move drag handle visual to the new date cell // var cell = _grid.Children.OfType<CalendarCellView>().FirstOrDefault(c => (DateTime)c.BindingContext == newDate.Value.Date); if (cell != null) { var handleVisual = dragger == _rightResizeHandleDragger ? _rightResizeHandle : _leftResizeHandle; Grid.SetColumn(handleVisual, Grid.GetColumn(cell)); Grid.SetRow(handleVisual, Grid.GetRow(cell)); } }
/// <summary> /// Highlights destination cells during drag /// </summary> private void HandleDragging(object sender, DragEventArgs args) { var label = sender as DraggableView; if (label == null) { return; } var ev = label.BindingContext as Event; if (ev == null) { return; } var destinationPoint = GetDragDestinationPoint(args.Center, label); var newDate = GetDateAtPoint(destinationPoint); if (newDate.HasValue) { // Offset for this not being the first label of the event newDate = newDate.Value.AddDays(-_dragLabelDayOffset); var newRange = new TimeRange(ev.Start, ev.End); newRange.MoveToDate(newDate.Value); // Highlight target cells, un-highlight previously-targeted cells // HighlightCells(newRange.StartDate, newRange.EndDate); } }
/// <summary> /// Resize the event and reset the resize mode state /// </summary> /// <param name="sender">Resize handle dragger</param> /// <param name="args">Drag event args</param> private void HandleResizeDragged(object sender, DragEventArgs args) { var dragger = sender as DraggableView; if (dragger == null) { return; } SynchronizeResizeHandleDraggersWithVisuals(); // We were already updating _resizeRange during the drag, so now we just apply // (even on the off-chance that the Dragged coordinate differs significantly from the last // Dragging coordinate, it seems like we should respect the resize preview visual to // avoid surprising the user) // UpdateEvent(_resizingEvent, _resizeRange); }
/// <summary> /// Moves the dragged event to a new calendar grid cell(s) and updates its start/end dates accordingly. /// Uses the cell under the centerpoint of the first day. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void HandleDragged(object sender, DragEventArgs args) { // Reset cell highlights UnhighlightCells(); var label = sender as DraggableView; if (label == null) { return; } var ev = label.BindingContext as Event; if (ev == null) { return; } var destinationPoint = GetDragDestinationPoint(args.Center, label); // Perform hit detection // var newDate = GetDateAtPoint(destinationPoint); if (newDate.HasValue) { // Offset for this not being the first label of the event newDate = newDate.Value.AddDays(-_dragLabelDayOffset); MoveEvent(ev, newDate.Value); } // Reset opacity SetEventOpacity(ev, 1.0); }