diff --git a/src/Avalonia.Controls/Repeater/ItemsSourceView.cs b/src/Avalonia.Controls/ItemsSourceView.cs
similarity index 84%
rename from src/Avalonia.Controls/Repeater/ItemsSourceView.cs
rename to src/Avalonia.Controls/ItemsSourceView.cs
index e84d97784a..2836937b79 100644
--- a/src/Avalonia.Controls/Repeater/ItemsSourceView.cs
+++ b/src/Avalonia.Controls/ItemsSourceView.cs
@@ -15,23 +15,17 @@ using Avalonia.Controls.Utils;
namespace Avalonia.Controls
{
///
- /// Represents a standardized view of the supported interactions between a given ItemsSource
- /// object and an control.
+ /// Represents a standardized view of the supported interactions between a given
+ /// or and its items.
///
- ///
- /// Components written to work with ItemsRepeater should consume the
- /// via ItemsSourceView since this provides a normalized
- /// view of the Items. That way, each component does not need to know if the source is an
- /// IEnumerable, an IList, or something else.
- ///
public class ItemsSourceView : INotifyCollectionChanged, IDisposable, IReadOnlyList
{
///
- /// Gets an empty
+ /// Gets an empty
///
public static ItemsSourceView Empty { get; } = new ItemsSourceView(Array.Empty());
- private readonly IList _inner;
+ private readonly IList _inner;
private INotifyCollectionChanged? _notifyCollectionChanged;
///
@@ -47,17 +41,17 @@ namespace Avalonia.Controls
{
source = source ?? throw new ArgumentNullException(nameof(source));
- if (source is IList list)
+ if (source is IList list)
{
_inner = list;
}
- else if (source is IEnumerable objectEnumerable)
+ else if (source is IEnumerable
/// The index.
/// The item.
- public T GetAt(int index) => _inner[index];
+ public T GetAt(int index) => _inner is IList typed ? typed[index] : (T)_inner[index];
- public int IndexOf(T item) => _inner.IndexOf(item);
+ public int IndexOf(object? item) => _inner.IndexOf(item);
public static ItemsSourceView GetOrCreate(IEnumerable? items)
{
@@ -148,7 +142,9 @@ namespace Avalonia.Controls
throw new NotImplementedException();
}
- public IEnumerator GetEnumerator() => _inner.GetEnumerator();
+ public IEnumerator GetEnumerator() => _inner is IList typed ?
+ typed.GetEnumerator() : _inner.Cast().GetEnumerator();
+
IEnumerator IEnumerable.GetEnumerator() => _inner.GetEnumerator();
internal void AddListener(ICollectionChangedListener listener)
@@ -187,7 +183,7 @@ namespace Avalonia.Controls
}
}
- public class ItemsSourceView : ItemsSourceView
+ public class ItemsSourceView : ItemsSourceView
{
public ItemsSourceView(IEnumerable source)
: base(source)