diff --git a/ch08_HotStuff/DragNDrop/ExchangeNounoursPage.xaml.cs b/ch08_HotStuff/DragNDrop/ExchangeNounoursPage.xaml.cs
index 61c4e32..7ac7522 100644
--- a/ch08_HotStuff/DragNDrop/ExchangeNounoursPage.xaml.cs
+++ b/ch08_HotStuff/DragNDrop/ExchangeNounoursPage.xaml.cs
@@ -24,7 +24,7 @@ public partial class ExchangeNounoursPage : ContentPage
private void OnDragStarting(object sender, DragStartingEventArgs e)
{
- e.Data.Properties["value"] = (sender as Element)?.Parent.BindingContext;
+ e.Data.Properties["value"] = (sender as Element)?.BindingContext;
}
private void OnDrop(object sender, DropEventArgs e)
diff --git a/ch08_HotStuff/DragNDrop/InCellsPage.xaml b/ch08_HotStuff/DragNDrop/InCellsPage.xaml
index 08adf70..c90fead 100644
--- a/ch08_HotStuff/DragNDrop/InCellsPage.xaml
+++ b/ch08_HotStuff/DragNDrop/InCellsPage.xaml
@@ -66,8 +66,8 @@
Radius="10" Opacity="0.8"/>
-
-
+
+
diff --git a/ch08_HotStuff/DragNDrop/InCellsPage.xaml.cs b/ch08_HotStuff/DragNDrop/InCellsPage.xaml.cs
index 72f84f9..ec5feac 100644
--- a/ch08_HotStuff/DragNDrop/InCellsPage.xaml.cs
+++ b/ch08_HotStuff/DragNDrop/InCellsPage.xaml.cs
@@ -23,9 +23,9 @@ public partial class InCellsPage : ContentPage
BindingContext = this;
}
- private void DropGestureRecognizer_Drop(object sender, DropEventArgs e)
+ private void Cages_Drop(object sender, DropEventArgs e)
{
- if ((sender as Element)?.Parent.BindingContext is Cage receivingElement)
+ if ((sender as Element)?.BindingContext is Cage receivingElement)
{
if (e.Data.Properties["value"] is Nounours draggedNounours)
{
@@ -36,19 +36,12 @@ public partial class InCellsPage : ContentPage
private void Bag_DragStarting(object sender, DragStartingEventArgs e)
{
- e.Data.Properties["value"] = (sender as Element)?.Parent.BindingContext;
+ e.Data.Properties["value"] = (sender as Element)?.BindingContext;
}
- private void DropGestureRecognizer_DragLeave(object sender, DragEventArgs e)
+ private void Cages_DragStarting(object sender, DragStartingEventArgs 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;
+ e.Data.Properties["value"] = ((sender as Element)?.BindingContext as Cage)?.MyPrecious;
if((sender as Element)?.BindingContext is Cage cage)
cage.MyPrecious = null;
}
diff --git a/ch08_HotStuff/DragNDrop/OrganizeNounoursPage.xaml.cs b/ch08_HotStuff/DragNDrop/OrganizeNounoursPage.xaml.cs
index 9133b5c..d2c37d6 100644
--- a/ch08_HotStuff/DragNDrop/OrganizeNounoursPage.xaml.cs
+++ b/ch08_HotStuff/DragNDrop/OrganizeNounoursPage.xaml.cs
@@ -22,23 +22,22 @@ public partial class OrganizeNounoursPage : ContentPage
private void OnDragStarting(object sender, DragStartingEventArgs e)
{
- e.Data.Properties["value"] = (sender as Element)?.Parent.BindingContext;
+ e.Data.Properties["value"] = (sender as Element)?.BindingContext;
}
private void OnDrop(object sender, DropEventArgs e)
{
- var receivingElement = (sender as Element)?.Parent.BindingContext as Nounours;
-
- var draggedElement = e.Data.Properties["value"] as Nounours;
-
+ if ((sender as Element)?.BindingContext is not Nounours receivingElement) return;
+ if (e.Data.Properties["value"] as Nounours is not Nounours draggedElement) return;
int draggedIndex = NounoursCollection.IndexOf(draggedElement);
- if (NounoursCollection.Contains(draggedElement))
+ if (draggedIndex > -1)
{
NounoursCollection.RemoveAt(draggedIndex);
}
int receivingIndex = NounoursCollection.IndexOf(receivingElement);
+ if (receivingIndex == -1) throw new ArgumentNullException("There should be a receiving element");
if (receivingIndex >= draggedIndex)
{