diff --git a/src/Controls/src/Core/Cells/Cell.cs b/src/Controls/src/Core/Cells/Cell.cs index 2da47d8120ec..c82f661fe2b6 100644 --- a/src/Controls/src/Core/Cells/Cell.cs +++ b/src/Controls/src/Core/Cells/Cell.cs @@ -273,7 +273,7 @@ async void OnForceUpdateSizeRequested() // don't run more than once per 16 milliseconds await Task.Delay(TimeSpan.FromMilliseconds(16)); ForceUpdateSizeRequested?.Invoke(this, null); - Handler.Invoke("ForceUpdateSizeRequested", null); + Handler?.Invoke("ForceUpdateSizeRequested", null); _nextCallToForceUpdateSizeQueued = false; } diff --git a/src/Controls/tests/Core.UnitTests/ListViewTests.cs b/src/Controls/tests/Core.UnitTests/ListViewTests.cs index e1bd22ce486f..78fe5abcbb10 100644 --- a/src/Controls/tests/Core.UnitTests/ListViewTests.cs +++ b/src/Controls/tests/Core.UnitTests/ListViewTests.cs @@ -1649,5 +1649,25 @@ public void DoesNotRetainInRecycleMode() Assert.False(ReferenceEquals(item1, item2)); } + + [Fact] + public void ForceUpdateSizeCalledOnViewCellDoesntCrash() + { + var list = new ListView(){ + HasUnevenRows = true + }; + + list.ItemTemplate = new DataTemplate(() => + { + return new ViewCell { View = new Label() }; + } + ); + + list.ItemsSource = new[] { "Hi" }; + + var element = (ViewCell)list.TemplatedItems[0]; + + element.ForceUpdateSize(); + } } }