diff --git a/src/BlazorBindings.Maui/Elements/Internal/ItemsSourceComponent.cs b/src/BlazorBindings.Maui/Elements/Internal/ItemsSourceComponent.cs index 8028addf..dbe4e69c 100644 --- a/src/BlazorBindings.Maui/Elements/Internal/ItemsSourceComponent.cs +++ b/src/BlazorBindings.Maui/Elements/Internal/ItemsSourceComponent.cs @@ -18,14 +18,10 @@ internal class ItemsSourceComponent : NativeControlComponentBas [Parameter] public Action> CollectionSetter { get; set; } - [Parameter] - public Func KeySelector { get; set; } - - private TControl _parent; public object TargetElement => _parent; - private HashSet _keys; + private readonly HashSet _keys = new(); protected override RenderFragment GetChildContent() => builder => { @@ -35,16 +31,11 @@ protected override RenderFragment GetChildContent() => builder => int index = 0; foreach (var item in Items) { - var key = KeySelector == null ? item : KeySelector(item); - if (KeySelector == null) - { - // Blazor doesn't allow duplicate keys. Therefore we add keys until the first duplicate. - // In case KeySelector is provided, we don't check for that here, since it's user's responsibility now. - _keys ??= new(); - shouldAddKey &= _keys.Add(key); - if (!shouldAddKey) - key = null; - } + object key = item; + // Blazor doesn't allow duplicate keys. Therefore we add keys only until the first duplicate. + shouldAddKey &= _keys.Add(key); + if (!shouldAddKey) + key = null; builder.OpenComponent(1); builder.SetKey(key);