Browse Source

Fix AlwaysSelected selected state.

Fixes #2901. Two things needed to be done here:

- When an item is removed, causing indexes to be reassigned, raise `Recycled` so that `SelectingItemsControl` knows to update the selection state
- Update selection state in `SelectingItemsControl` when the selected item changes, but the selected index does not (due to an item being remove)
pull/2922/head
Steven Kirk 7 years ago
parent
commit
5de0bf5fec
  1. 6
      src/Avalonia.Controls/Generators/ItemContainerGenerator.cs
  2. 5
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

6
src/Avalonia.Controls/Generators/ItemContainerGenerator.cs

@ -128,6 +128,12 @@ namespace Avalonia.Controls.Generators
}
Dematerialized?.Invoke(this, new ItemContainerEventArgs(startingIndex, result));
if (toMove.Count > 0)
{
var containers = toMove.Select(x => x.Value).ToList();
Recycled?.Invoke(this, new ItemContainerEventArgs(containers[0].Index, containers));
}
}
return result;

5
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

@ -979,13 +979,14 @@ namespace Avalonia.Controls.Primitives
}
var item = ElementAt(Items, index);
var itemChanged = !Equals(item, oldItem);
var added = -1;
HashSet<int> removed = null;
_selectedIndex = index;
_selectedItem = item;
if (oldIndex != index || _selection.HasMultiple)
if (oldIndex != index || itemChanged || _selection.HasMultiple)
{
if (clear)
{
@ -1022,7 +1023,7 @@ namespace Avalonia.Controls.Primitives
index);
}
if (!Equals(item, oldItem))
if (itemChanged)
{
RaisePropertyChanged(
SelectedItemProperty,

Loading…
Cancel
Save