From 3b11401558678a27d6c6f5103e58252de04761f0 Mon Sep 17 00:00:00 2001 From: juliuszint Date: Mon, 26 Jun 2017 20:29:23 +0200 Subject: [PATCH] Unsubscribe from IDefinition.SizeChanged event when set via indexer (#1014) * Unsubscribe from IDefinition.SizeChanged event when set via indexer * added bounds and null check to preserve original exception * index check for negative values --- Xamarin.Forms.Core/DefinitionCollection.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Xamarin.Forms.Core/DefinitionCollection.cs b/Xamarin.Forms.Core/DefinitionCollection.cs index bf0e4d06f..6310a4212 100644 --- a/Xamarin.Forms.Core/DefinitionCollection.cs +++ b/Xamarin.Forms.Core/DefinitionCollection.cs @@ -83,6 +83,9 @@ namespace Xamarin.Forms get { return _internalList[index]; } set { + if(index < _internalList.Count && _internalList[index] != null && index >= 0) + _internalList[index].SizeChanged -= OnItemSizeChanged; + _internalList[index] = value; value.SizeChanged += OnItemSizeChanged; OnItemSizeChanged(this, EventArgs.Empty); @@ -106,4 +109,4 @@ namespace Xamarin.Forms eh(this, EventArgs.Empty); } } -} \ No newline at end of file +}