diff --git a/.gitignore b/.gitignore
index bbf358b8f4..ee778ed4e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -102,6 +102,7 @@ csx
AppPackages/
# NCrunch
+.NCrunch_*/
_NCrunch_*/
*.ncrunchsolution.user
nCrunchTemp_*
diff --git a/src/Avalonia.Controls/ItemsSourceView.cs b/src/Avalonia.Controls/ItemsSourceView.cs
index c8fc76255c..416b909219 100644
--- a/src/Avalonia.Controls/ItemsSourceView.cs
+++ b/src/Avalonia.Controls/ItemsSourceView.cs
@@ -27,6 +27,7 @@ namespace Avalonia.Controls
private readonly IList _inner;
private NotifyCollectionChangedEventHandler? _collectionChanged;
+ private NotifyCollectionChangedEventHandler? _preCollectionChanged;
private NotifyCollectionChangedEventHandler? _postCollectionChanged;
private bool _listening;
@@ -70,7 +71,7 @@ namespace Avalonia.Controls
/// Gets a value that indicates whether the items source can provide a unique key for each item.
///
///
- /// TODO: Not yet implemented in Avalonia.
+ /// Not implemented in Avalonia, preserved here for ItemsRepeater's usage.
///
internal bool HasKeyIndexMapping => false;
@@ -92,6 +93,25 @@ namespace Avalonia.Controls
}
}
+ ///
+ /// Occurs when a collection has finished changing and all
+ /// event handlers have been notified.
+ ///
+ internal event NotifyCollectionChangedEventHandler? PreCollectionChanged
+ {
+ add
+ {
+ AddListenerIfNecessary();
+ _preCollectionChanged += value;
+ }
+
+ remove
+ {
+ _preCollectionChanged -= value;
+ RemoveListenerIfNecessary();
+ }
+ }
+
///
/// Occurs when a collection has finished changing and all
/// event handlers have been notified.
@@ -229,6 +249,7 @@ namespace Avalonia.Controls
void ICollectionChangedListener.PreChanged(INotifyCollectionChanged sender, NotifyCollectionChangedEventArgs e)
{
+ _preCollectionChanged?.Invoke(this, e);
}
void ICollectionChangedListener.Changed(INotifyCollectionChanged sender, NotifyCollectionChangedEventArgs e)
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