|
|
@ -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", |
|
|
|