Browse Source
Merge pull request #2510 from AvaloniaUI/fixes/2507-carousel-exception
Only generate containers on the fly if virtualized.
pull/2511/head
Wiesław Šoltés
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
24 additions and
1 deletions
-
src/Avalonia.Controls/Presenters/CarouselPresenter.cs
-
tests/Avalonia.Controls.UnitTests/CarouselTests.cs
|
|
|
@ -210,7 +210,7 @@ namespace Avalonia.Controls.Presenters |
|
|
|
{ |
|
|
|
var container = ItemContainerGenerator.ContainerFromIndex(index); |
|
|
|
|
|
|
|
if (container == null) |
|
|
|
if (container == null && IsVirtualized) |
|
|
|
{ |
|
|
|
var item = Items.Cast<object>().ElementAt(index); |
|
|
|
var materialized = ItemContainerGenerator.Materialize(index, item, MemberSelector); |
|
|
|
|
|
|
|
@ -152,6 +152,29 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Equal("Bar", ((TextBlock)child).Text); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Selected_Item_Changes_To_First_Item_When_Item_Added() |
|
|
|
{ |
|
|
|
var items = new ObservableCollection<string>(); |
|
|
|
var target = new Carousel |
|
|
|
{ |
|
|
|
Template = new FuncControlTemplate<Carousel>(CreateTemplate), |
|
|
|
Items = items, |
|
|
|
IsVirtualized = false |
|
|
|
}; |
|
|
|
|
|
|
|
target.ApplyTemplate(); |
|
|
|
target.Presenter.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal(-1, target.SelectedIndex); |
|
|
|
Assert.Empty(target.GetLogicalChildren()); |
|
|
|
|
|
|
|
items.Add("Foo"); |
|
|
|
|
|
|
|
Assert.Equal(0, target.SelectedIndex); |
|
|
|
Assert.Single(target.GetLogicalChildren()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Selected_Index_Changes_To_When_Items_Assigned_Null() |
|
|
|
{ |
|
|
|
|