diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/ListViewRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/ListViewRenderer.cs index 942adb97ce67..1b5c24b9fd15 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/ListViewRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/ListViewRenderer.cs @@ -260,8 +260,6 @@ void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) ClearSizeEstimate(); ReloadData(); } - - Element.Dispatcher.DispatchIfRequired(() => List?.UpdateLayout()); } protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) diff --git a/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.Windows.cs b/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.Windows.cs index 44ad92d6f3e0..79e673dd5da6 100644 --- a/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.Windows.cs +++ b/src/Controls/tests/DeviceTests/Elements/ListView/ListViewTests.Windows.cs @@ -1,9 +1,16 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Handlers.Compatibility; +using Microsoft.Maui.Controls.Platform; +using Microsoft.Maui.Handlers; +using Microsoft.Maui.Platform; +using Microsoft.UI.Xaml; +using Xunit; namespace Microsoft.Maui.DeviceTests { @@ -14,5 +21,38 @@ void ValidatePlatformCells(ListView listView) { } + + [Fact] + public async Task InsertItemWorks() + { + SetupBuilder(); + + var data = new ObservableCollection(); + var listView = new ListView() + { + ItemsSource = data + }; + + var layout = new VerticalStackLayout() + { + listView + }; + + await CreateHandlerAndAddToWindow(layout, async (handler) => + { + await Task.Delay(100); + + data.Add("Item 1"); + data.Add("Item 3"); + data.Insert(1, "Item 2"); + + await Task.Delay(200); + + var actualListView = listView.ToPlatform() as ListViewRenderer; + var textChildren = actualListView.GetChildren(); + + Assert.Contains(textChildren, (x) => x.Text == "Item 3"); + }); + } } -} \ No newline at end of file +}