|
|
|
@ -1,6 +1,8 @@ |
|
|
|
// Copyright (c) The Avalonia Project. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See licence.md file in the project root for full license information.
|
|
|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Specialized; |
|
|
|
using Avalonia.Collections; |
|
|
|
using Avalonia.Controls.Presenters; |
|
|
|
using Avalonia.Controls.Primitives; |
|
|
|
@ -43,6 +45,24 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
Assert.Equal("foo", target.SelectedItem); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void First_Item_Should_Be_Selected_When_Reset() |
|
|
|
{ |
|
|
|
var items = new ResetOnAdd(); |
|
|
|
var target = new TestSelector |
|
|
|
{ |
|
|
|
Items = items, |
|
|
|
Template = Template(), |
|
|
|
}; |
|
|
|
|
|
|
|
target.ApplyTemplate(); |
|
|
|
items.Add("foo"); |
|
|
|
|
|
|
|
Assert.Equal(0, target.SelectedIndex); |
|
|
|
Assert.Equal("foo", target.SelectedItem); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Item_Should_Be_Selected_When_Selection_Removed() |
|
|
|
{ |
|
|
|
@ -100,5 +120,18 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
SelectionModeProperty.OverrideDefaultValue<TestSelector>(SelectionMode.AlwaysSelected); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private class ResetOnAdd : List<string>, INotifyCollectionChanged |
|
|
|
{ |
|
|
|
public event NotifyCollectionChangedEventHandler CollectionChanged; |
|
|
|
|
|
|
|
public new void Add(string item) |
|
|
|
{ |
|
|
|
base.Add(item); |
|
|
|
CollectionChanged?.Invoke( |
|
|
|
this, |
|
|
|
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|