Browse Source

Merge branch 'master' into fixes/1932-dropdown-selection

pull/1933/head
Steven Kirk 8 years ago
committed by GitHub
parent
commit
031cc61c90
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/Avalonia.Controls/Generators/ItemContainerGenerator.cs
  2. 34
      tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

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

@ -15,7 +15,7 @@ namespace Avalonia.Controls.Generators
/// </summary> /// </summary>
public class ItemContainerGenerator : IItemContainerGenerator public class ItemContainerGenerator : IItemContainerGenerator
{ {
private Dictionary<int, ItemContainerInfo> _containers = new Dictionary<int, ItemContainerInfo>(); private SortedDictionary<int, ItemContainerInfo> _containers = new SortedDictionary<int, ItemContainerInfo>();
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ItemContainerGenerator"/> class. /// Initializes a new instance of the <see cref="ItemContainerGenerator"/> class.
@ -246,4 +246,4 @@ namespace Avalonia.Controls.Generators
Recycled?.Invoke(this, e); Recycled?.Invoke(this, e);
} }
} }
} }

34
tests/Avalonia.Controls.UnitTests/ListBoxTests.cs

@ -1,16 +1,18 @@
// Copyright (c) The Avalonia Project. All rights reserved. // 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. // Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Avalonia.Collections;
using Avalonia.Controls.Presenters; using Avalonia.Controls.Presenters;
using Avalonia.Controls.Templates; using Avalonia.Controls.Templates;
using Avalonia.Input; using Avalonia.Data;
using Avalonia.LogicalTree; using Avalonia.LogicalTree;
using Avalonia.Styling; using Avalonia.Styling;
using Avalonia.UnitTests; using Avalonia.UnitTests;
using Avalonia.VisualTree; using Avalonia.VisualTree;
using Xunit; using Xunit;
using Avalonia.Collections;
namespace Avalonia.Controls.UnitTests namespace Avalonia.Controls.UnitTests
{ {
@ -170,9 +172,33 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(new Size(100, 10), target.Scroll.Viewport); Assert.Equal(new Size(100, 10), target.Scroll.Viewport);
} }
[Fact]
public void Containers_Correct_After_Clear_Add_Remove()
{
// Issue #1936
var items = new AvaloniaList<string>(Enumerable.Range(0, 11).Select(x => $"Item {x}"));
var target = new ListBox
{
Template = ListBoxTemplate(),
Items = items,
ItemTemplate = new FuncDataTemplate<string>(x => new TextBlock { Width = 20, Height = 10 }),
SelectedIndex = 0,
};
Prepare(target);
items.Clear();
items.AddRange(Enumerable.Range(0, 11).Select(x => $"Item {x}"));
items.Remove("Item 2");
Assert.Equal(
items,
target.Presenter.Panel.Children.Cast<ListBoxItem>().Select(x => (string)x.Content));
}
private FuncControlTemplate ListBoxTemplate() private FuncControlTemplate ListBoxTemplate()
{ {
return new FuncControlTemplate<ListBox>(parent => return new FuncControlTemplate<ListBox>(parent =>
new ScrollViewer new ScrollViewer
{ {
Name = "PART_ScrollViewer", Name = "PART_ScrollViewer",
@ -189,7 +215,7 @@ namespace Avalonia.Controls.UnitTests
private FuncControlTemplate ListBoxItemTemplate() private FuncControlTemplate ListBoxItemTemplate()
{ {
return new FuncControlTemplate<ListBoxItem>(parent => return new FuncControlTemplate<ListBoxItem>(parent =>
new ContentPresenter new ContentPresenter
{ {
Name = "PART_ContentPresenter", Name = "PART_ContentPresenter",

Loading…
Cancel
Save