using System.Collections.ObjectModel; using DragNDrop.Model; namespace DragNDrop; public partial class ExchangeNounoursPage : ContentPage { public ObservableCollection FirstCollection { get; set; } = new ObservableCollection() { new Nounours(42, "Chewbacca"), new Nounours(43, "Yoda"), new Nounours(44, "Ewok"), new Nounours(45, "Jabba the Hutt"), new Nounours(666, "Chucky") }; public ObservableCollection SecondCollection { get; set; } = new ObservableCollection(); public ExchangeNounoursPage() { InitializeComponent(); BindingContext = this; } private void OnDragStarting(object sender, DragStartingEventArgs e) { e.Data.Properties["value"] = (sender as Element)?.BindingContext; } private void OnDrop(object sender, DropEventArgs e) { var collection = ((sender as Element)?.Parent as FlexLayout).GetPropertyIfSet>(BindableLayout.ItemsSourceProperty, null); if (e.Data.Properties["value"] is Nounours nounours) { FirstCollection.Remove(nounours); SecondCollection.Remove(nounours); collection.Add(nounours); } } }