/// <summary> /// Handler changes drag cursor and starts timer to expand route's details /// when user drags any order over row. /// </summary> /// <param name="sender">Row.</param> /// <param name="e">Drag event args.</param> private void _DragOverRow(object sender, DragEventArgs e) { var draggedOverRow = sender as Row; Object dragOveredObject = draggedOverRow.DataContext; var dragAndDropHelper = new DragAndDropHelper(); // Check if Drag&Drop operation allowed. ICollection<Order> orders = dragAndDropHelper.GetDraggingOrders(e.Data); bool isDropAllowed = dragAndDropHelper.DoesDropAllowed(dragOveredObject, orders); if (!isDropAllowed) { e.Effects = DragDropEffects.None; e.Handled = true; } else e.Effects = DragDropEffects.Move; // If dragged over route has stops and timer disabled (not turned on yet or already // turned off) - start timer and remember context. var route = dragOveredObject as Route; if ((null != route) && route.Stops != null && route.Stops.Count > 0 && _expandTimer.Enabled == false) { _expandTimer.Enabled = true; _expandTimer.Start(); _currentRowToExpand = ((Row)sender).DataContext; } }
/// <summary> /// Method checks is dragging allowed and starts dragging if possible. /// </summary> private void _TryToStartDragging() { Collection<object> selection = _GetSelectedStops(); DragAndDropHelper dragAndDropHelper = new DragAndDropHelper(); bool isDragAllowed = dragAndDropHelper.IsDragAllowed(selection); if (isDragAllowed && selection.Count > 0) { // we use deferred call to allow grid complete BringItemIntoView this.Dispatcher.BeginInvoke(new Action(delegate() { dragAndDropHelper.StartDragOrders(selection, DragSource.RoutesView); })); } }
/// <summary> /// Drops objects to grid. /// </summary> /// <param name="sender">Data grid control sender.</param> /// <param name="e">Event args.</param> private void _DataGridControlDrop(object sender, DragEventArgs e) { // Get row where object was dropped. Row parentRow = XceedVisualTreeHelper.GetRowByEventArgs(e); if (parentRow == null) return; // Get data from dropped object. object targetData = _GetTargetData(parentRow); // Do necessary actions (move or reassign routes etc.). DragAndDropHelper dragAndDropHelper = new DragAndDropHelper(); dragAndDropHelper.Drop(targetData, e.Data); }
/// <summary> /// Fired when an object is dropped on the calendar. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void calendar_Drop(object sender, DragEventArgs e) { DragAndDropHelper dragAndDropHelper = new DragAndDropHelper(); FrameworkElement targetFrameworkElement = (FrameworkElement)e.OriginalSource; Object context = targetFrameworkElement.DataContext; while (!(context is DateTime)) { targetFrameworkElement = (FrameworkElement)VisualTreeHelper.GetParent(targetFrameworkElement); context = targetFrameworkElement.DataContext; Debug.Assert(context != null); // context shouldn't be null } DateTime targetDate = (DateTime)context; if (targetDate != null) dragAndDropHelper.DropOnDate(targetDate, e.Data); }