Dragging items in gridview
I have a grid with a dynamic number of rows and 3 columns. Only 3 rows are visible at a certain moment. In grid I can have empty cells. Do you have any idea how to implement a drag/drop feature for the view on a view from a cell? I want to be able to d开发者_JAVA技巧rag items in empty cells.
Here i wish to add one more example, reference and some code snippet.
Dragging Code Let’s look at the control implementation and how we handle dragging items.
public class GridViewEx : GridView { /// <summary> /// Initializes a new instance of the <see cref="GridViewEx"/> control. /// </summary> public GridViewEx() { // see attached sample } private void GridViewEx_DragItemsStarting(object sender, DragItemsStartingEventArgs e) { // see attached sample } /// <summary> /// Stores dragged items into DragEventArgs.Data.Properties["Items"] value. /// Override this method to set custom drag data if you need to. /// </summary> protected virtual void OnDragStarting(DragItemsStartingEventArgs e) { // see attached sample } The control has several fields which store the indices of several active items during the drag/drop process. The OnDragStarting
event stores dragged items into the DragEventArgs.Data.Properties[“Items”] value. You would override this method to set custom drag data if you need to. When the user drags an item, we need to show hints as to where the item will be placed if dropped. The standard GridView handles this by sliding adjacent items out of the way. We will implement this exact behavior ourselves in GridViewEx because we need to account for cases where GridView does not support dropping.
/// <summary> /// Shows reoder hints while custom dragging. /// </summary> protected override void OnDragOver(DragEventArgs e) { // see attached sample } private int GetDragOverIndex(DragEventArgs e) { // see attached sample } Dropping Code Next, let’s look at the code that handles dropping. We have to override GridView.OnDrop method which is called every time when an end-user drops an item to the new location. Our override
handles dropping for any ItemsPanel that the standard GridView does not support dropping.
/// <summary> /// Handles drag and drop for cases when it is not supported by the Windows.UI.Xaml.Controls.GridView control /// </summary> protected override async void OnDrop(DragEventArgs e) { // see attached sample } The OnDrop method includes logic for moving items from one group to another when grouping is enabled, and for new group creation if it
is requested by end-user actions.
For more details you can refer following linksExtending GridView with Drag and Drop for Grouping and Variable Sized Items
You can follow the below link too Android Drag and Drop Example
Hope, this may help you.
精彩评论