When using an ObservableList with a view, the move event gets duplicated. This causes issues with synchronized UI controls (Avalonia in my example) which then move their items around twice causing invalid states.
I'm working on a fix for this in a fork, can open a PR to merge following, however I haven't had much response from Cysharp lately.
private static void TestObservableList()
{
var values = new ObservableList<int> { 0, 1, 2, 3 };
var valuesView = values
.ToNotifyCollectionChanged();
int moveEventCount = 0;
valuesView.CollectionChanged += (sender, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Move)
moveEventCount++;
};
values.Move(0, 1);
Debug.Assert(moveEventCount == 1);
}
private static void TestObservableListWithView()
{
var values = new ObservableList<int> { 0, 1, 2, 3 };
var valuesView = values.CreateView(i => i)
.ToNotifyCollectionChanged();
int moveEventCount = 0;
valuesView.CollectionChanged += (sender, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Move)
moveEventCount++;
};
values.Move(0, 1);
// Fails, always == 2
Debug.Assert(moveEventCount == 1);
}
When using an ObservableList with a view, the move event gets duplicated. This causes issues with synchronized UI controls (Avalonia in my example) which then move their items around twice causing invalid states.
I'm working on a fix for this in a fork, can open a PR to merge following, however I haven't had much response from Cysharp lately.