Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Fix ListView insert not working properly #22746

Merged
merged 4 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -14,5 +21,38 @@ void ValidatePlatformCells(ListView listView)
{

}

[Fact]
public async Task InsertItemWorks()
{
SetupBuilder();

var data = new ObservableCollection<string>();
var listView = new ListView()
{
ItemsSource = data
};

var layout = new VerticalStackLayout()
{
listView
};

await CreateHandlerAndAddToWindow<LayoutHandler>(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<UI.Xaml.Controls.TextBlock>();

Assert.True(textChildren.Any(x => x.Text == "Item 3"));
});
}
}
}
Loading