using System.Collections.ObjectModel; using DragNDrop.Model; namespace DragNDrop; public partial class InCellsPage : 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(new int[10].Select(i => new Cage())); public InCellsPage() { InitializeComponent(); BindingContext = this; } private void DropGestureRecognizer_Drop(object sender, DropEventArgs e) { if ((sender as Element)?.Parent.BindingContext is Cage receivingElement) { if (e.Data.Properties["value"] is Nounours draggedNounours) { receivingElement.MyPrecious = draggedNounours; } } } private void Bag_DragStarting(object sender, DragStartingEventArgs e) { e.Data.Properties["value"] = (sender as Element)?.Parent.BindingContext; } private void DropGestureRecognizer_DragLeave(object sender, DragEventArgs e) { if(e.Data.Properties["value"] is Nounours draggedNounours && sender is Cage cage) cage.MyPrecious = null; } private void DragGestureRecognizer_DragStarting1(object sender, DragStartingEventArgs e) { e.Data.Properties["value"] = ((sender as Element)?.Parent.BindingContext as Cage)?.MyPrecious; if((sender as Element)?.BindingContext is Cage cage) cage.MyPrecious = null; } }