You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
using System.Collections.ObjectModel;
|
|
using DragNDrop.Model;
|
|
|
|
namespace DragNDrop;
|
|
|
|
public partial class InCellsPage : ContentPage
|
|
{
|
|
public ObservableCollection<Nounours> FirstCollection { get; set; } = new ObservableCollection<Nounours>()
|
|
{
|
|
new Nounours(42, "Chewbacca"),
|
|
new Nounours(43, "Yoda"),
|
|
new Nounours(44, "Ewok"),
|
|
new Nounours(45, "Jabba the Hutt"),
|
|
new Nounours(666, "Chucky")
|
|
};
|
|
|
|
public ObservableCollection<Cage> SecondCollection { get; set; }
|
|
= new ObservableCollection<Cage>(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;
|
|
}
|
|
} |