void gvSelectedAlpha_OnDropInfo(object sender, DragDropEventArgs e) { if (e.Options.Status == DragStatus.DropPossible) { if (e.Options.Destination is GridViewCell) { DragDropHelper.ShowDropEffectForDropPossible(e.Options.Destination as GridViewCell); } } else if (e.Options.Status == DragStatus.DropComplete) { if (e.Options.Destination is GridViewCell) { DragDropHelper.ShowDropEffectForDropComplete(e.Options.Destination as GridViewCell); } } else if (e.Options.Status == DragStatus.DropImpossible) { DragDropHelper.ShowDropEffectForDropImpossible(e.Options.Destination); } }
public class DragDropHelper { public static void ShowDropEffect(GridViewRow row, bool show) { Border border = row.ChildrenOfType<Border>().Where(b => b.Name == "Background_Selected").FirstOrDefault(); if (border != null) border.Visibility = show == true ? Visibility.Visible : Visibility.Collapsed; } // show effect only for mouse over row but not for all other rows public static void ShowDropEffectForDropPossible(GridViewCell cell) { GridViewRow row = cell.ParentOfType<GridViewRow>(); ShowDropEffectForOnlyOneRow(row); } //after drop is complete remove drop effect for current row public static void ShowDropEffectForDropComplete(GridViewCell cell) { GridViewRow rowItem = cell.ParentOfType<GridViewRow>(); if (rowItem != null) { ShowDropEffect(rowItem, false); } } // show effect only for mouse over row but not for all other rows //drop location can be a cell or row level public static void ShowDropEffectForDropImpossible(object cell) { GridViewRow rowItem = null; if (cell is GridViewCell) { rowItem = ((GridViewCell)cell).ParentOfType<GridViewRow>(); } if (cell is GridViewRow) { rowItem = cell as GridViewRow; } if (rowItem !=null) ShowDropEffectForOnlyOneRow(rowItem); } public static void ShowDropEffectForOnlyOneRow(GridViewRow rowItem) { var rows = rowItem.GridViewDataControl.ChildrenOfType<GridViewRow>(); foreach (GridViewRow item in rows) { ShowDropEffect(item, false); } if (rowItem != null) { ShowDropEffect(rowItem, true); } } }