Browse Source

Auto-select when items added.

pull/4533/head
Steven Kirk 6 years ago
parent
commit
81b7b54386
  1. 31
      src/Avalonia.Controls/Primitives/SelectingItemsControl.cs

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

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using Avalonia.Controls.Generators; using Avalonia.Controls.Generators;
@ -274,27 +275,14 @@ namespace Avalonia.Controls.Primitives
return null; return null;
} }
/// <inheritdoc/> protected override void ItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
protected override void ItemsChanged(AvaloniaPropertyChangedEventArgs e)
{ {
base.ItemsChanged(e); base.ItemsCollectionChanged(sender, e);
//if (_updateCount == 0)
//{
// var newIndex = -1;
// if (SelectedIndex != -1) if (AlwaysSelected && SelectedIndex == -1 && ItemCount > 0)
// { {
// newIndex = IndexOf((IEnumerable)e.NewValue, SelectedItem); SelectedIndex = 0;
// } }
// if (AlwaysSelected && Items != null && Items.Cast<object>().Any())
// {
// newIndex = 0;
// }
// SelectedIndex = newIndex;
//}
} }
/// <inheritdoc/> /// <inheritdoc/>
@ -309,9 +297,10 @@ namespace Avalonia.Controls.Primitives
Selection.Select(container.Index); Selection.Select(container.Index);
MarkContainerSelected(container.ContainerControl, true); MarkContainerSelected(container.ContainerControl, true);
} }
else if (Selection.IsSelected(container.Index) == true) else
{ {
MarkContainerSelected(container.ContainerControl, true); var selected = Selection.IsSelected(container.Index);
MarkContainerSelected(container.ContainerControl, selected);
} }
} }
} }

Loading…
Cancel
Save