diff --git a/src/Avalonia.Controls/ItemsSourceView.cs b/src/Avalonia.Controls/ItemsSourceView.cs
index c8fc76255c..1fa8f6a5cf 100644
--- a/src/Avalonia.Controls/ItemsSourceView.cs
+++ b/src/Avalonia.Controls/ItemsSourceView.cs
@@ -241,6 +241,22 @@ namespace Avalonia.Controls
_postCollectionChanged?.Invoke(this, e);
}
+ internal void AddListener(ICollectionChangedListener listener)
+ {
+ if (Inner is INotifyCollectionChanged incc)
+ {
+ CollectionChangedEventManager.Instance.AddListener(incc, listener);
+ }
+ }
+
+ internal void RemoveListener(ICollectionChangedListener listener)
+ {
+ if (Inner is INotifyCollectionChanged incc)
+ {
+ CollectionChangedEventManager.Instance.RemoveListener(incc, listener);
+ }
+ }
+
///
/// Retrieves the index of the item that has the specified unique identifier (key).
///
diff --git a/src/Avalonia.Controls/Selection/InternalSelectionModel.cs b/src/Avalonia.Controls/Selection/InternalSelectionModel.cs
index d0715e402d..d0e6144f59 100644
--- a/src/Avalonia.Controls/Selection/InternalSelectionModel.cs
+++ b/src/Avalonia.Controls/Selection/InternalSelectionModel.cs
@@ -203,7 +203,7 @@ namespace Avalonia.Controls.Selection
}
}
- private protected override void OnSourceCollectionChanged(NotifyCollectionChangedEventArgs e)
+ protected override void OnSourceCollectionChanged(NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Reset)
{
diff --git a/src/Avalonia.Controls/Selection/SelectedItems.cs b/src/Avalonia.Controls/Selection/SelectedItems.cs
index ef642b7bdc..74007805cd 100644
--- a/src/Avalonia.Controls/Selection/SelectedItems.cs
+++ b/src/Avalonia.Controls/Selection/SelectedItems.cs
@@ -5,7 +5,7 @@ using System.Diagnostics.CodeAnalysis;
namespace Avalonia.Controls.Selection
{
- internal class SelectedItems : IReadOnlyList
+ internal class SelectedItems : IReadOnlyList
{
private readonly SelectionModel? _owner;
private readonly ItemsSourceView? _items;
@@ -19,12 +19,9 @@ namespace Avalonia.Controls.Selection
_items = items;
}
- [MaybeNull]
- public T this[int index]
+ public T? this[int index]
{
-#pragma warning disable CS8766
get
-#pragma warning restore CS8766
{
if (index >= Count)
{
@@ -64,15 +61,13 @@ namespace Avalonia.Controls.Selection
private ItemsSourceView? Items => _items ?? _owner?.ItemsView;
private IReadOnlyList? Ranges => _ranges ?? _owner!.Ranges;
- public IEnumerator GetEnumerator()
+ public IEnumerator GetEnumerator()
{
if (_owner?.SingleSelect == true)
{
if (_owner.SelectedIndex >= 0)
{
-#pragma warning disable CS8603
yield return _owner.SelectedItem;
-#pragma warning restore CS8603
}
}
else
@@ -83,9 +78,7 @@ namespace Avalonia.Controls.Selection
{
for (var i = range.Begin; i <= range.End; ++i)
{
-#pragma warning disable CS8603
yield return items is object ? items[i] : default;
-#pragma warning restore CS8603
}
}
}
@@ -102,8 +95,8 @@ namespace Avalonia.Controls.Selection
public class Untyped : IReadOnlyList