Skip to content

CollectionView Drag & Drop Item Reordering Spec #3767

@billvenhaus

Description

@billvenhaus

Description

Support drag-and-drop item reordering in the CollectionView.

The CollectionView handlers should use the built-in item reordering functionality provided by the platforms:

Reordering should require the CollectionView.ItemsSource be bound to an IList. The platform handlers will use the Remove & Insert methods on the IList to complete the reorder operation.

Example
https://github.com/billvenhaus/ReorderableCollectionView.Maui

reorderablecollectionview_ios

(Public) API Changes

Place the new reorder functionality in a separate class that the CollectionView can inherit.

CollectionView

public class CollectionView : ReorderableItemsView
{
}

ReorderableItemsView

public class ReorderableItemsView : GroupableItemsView
{
	public static readonly BindableProperty CanMixGroupsProperty;
	public bool CanMixGroups { get; set; }

	public static readonly BindableProperty CanReorderItemsProperty;
	public bool CanReorderItems { get; set; }

	public event EventHandler ReorderCompleted;
}

Properties

API Description
CanReorderItems Gets or sets a value that indicates whether items in the view can be reordered through user interaction.
CanMixGroups Gets or sets a value that indicates whether items from different groups can be mixed during reordering.

Events

API Description
ReorderCompleted Raised whenever reordering user interaction completes.

Usage Scenarios

Basic Item Reordering

The developer has an app which manages the playlist for a media player. The user needs to be able to make changes to the track order by rearranging the songs with drag-and-drop. How can the developer achieve this UI with the proposed API?

In order to achieve this behavior, the developer should set the CollectionView.CanReorderItems property to true. They can be notified of changes to the song order by subscribing to the ReorderCompleted event. At that point the developer can save the changes to the playlist storage location.

Reordering with Grouped Sources (Mixing Items)

The developer has a grouped data source & wishes to mix items. Items in group A can be placed in group B, and items in group B can be placed in group A. How can the developer achieve this with the proposed API?

In order to achieve this behavior, the developer should set both CollectionView.CanReorderItems & CollectionView.CanMixGroups to true.

Detailed Events

The ReorderCompleted is a basic EventHandler that doesn't provide any information about the item that moved. How can the developer determine which item moved & where it moved to?

The developer should bind the CollectionView.ItemsSource to an ObservableCollection if they need to know specific details about the item that moved. The CollectionChanged event of the ObservableCollection can provide that information.

Backward Compatibility

Minimum API Levels:

  • Available on all API levels.

Breaking Changes:

  • No breaking changes.

Unsupported Platforms:

  • Windows reordering only works with ObservableCollections
  • Windows reordering does not support grouped sources (see here)

Difficulty

Medium

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions