Здесь я хочу добавить еще один пример, ссылку и фрагмент кода.
Код перетаскивания
Давайте посмотрим на реализацию элемента управления и то, как мы обрабатываем перетаскивание элементов.
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
событие сохраняет перетаскиваемые объекты в
Значение DragEventArgs.Data.Properties [«Items»]. Вы бы переопределить это
метод, чтобы установить пользовательские данные перетаскивания, если вам нужно.
Когда пользователь перетаскивает элемент, нам нужно показать подсказки относительно того, куда он будет помещен, если его уронить. Стандартный GridView обрабатывает это
сдвинув соседние предметы в сторону. Мы будем реализовывать это точно
Поведение себя в GridViewEx, потому что мы должны учитывать случаи
где GridView не поддерживает удаление.
/// <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
обрабатывает удаление для любой ItemsPanel, что делает стандартный GridView
не поддерживает сброс.
/// <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
запрашивается действиями конечного пользователя.
Надеюсь, это может вам помочь.