@ -220,7 +220,7 @@ namespace Avalonia.Collections
/// <summary>
/// Removes all items from the collection.
/// </summary>
public void Clear()
public virtual void Clear()
{
if (this.Count > 0)
@ -86,6 +86,20 @@ namespace Avalonia.Controls
base.AddRange(c);
}
/// Remvoes all non-pseudoclasses from the collection.
public override void Clear()
for (var i = Count - 1; i >= 0; --i)
if (!this[i].StartsWith(":"))
RemoveAt(i);
/// Inserts a style class into the collection.
@ -149,5 +149,17 @@ namespace Avalonia.Controls.UnitTests
Assert.Throws<ArgumentException>(() => target.Replace(new[] { ":qux" }));
[Fact]
public void Clear_Should_Not_Remove_Pseudoclasses()
var target = new Classes("foo", "bar");
((IPseudoClasses)target).Add(":baz");
target.Clear();
Assert.Equal(new[] { ":baz" }, target);