Browse Source
Merge pull request #1711 from AvaloniaUI/fixes/1709-changing-listbox-template
Clear ItemContainerGenerator when ItemsPresenter changed.
pull/1714/head
Steven Kirk
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
47 additions and
4 deletions
-
src/Avalonia.Controls/ItemsControl.cs
-
src/Avalonia.Controls/Primitives/SelectingItemsControl.cs
-
src/Avalonia.Controls/Primitives/TemplatedControl.cs
-
tests/Avalonia.Controls.UnitTests/ItemsControlTests.cs
-
tests/Avalonia.Controls.UnitTests/Primitives/TemplatedControlTests.cs
|
|
|
@ -155,6 +155,7 @@ namespace Avalonia.Controls |
|
|
|
void IItemsPresenterHost.RegisterItemsPresenter(IItemsPresenter presenter) |
|
|
|
{ |
|
|
|
Presenter = presenter; |
|
|
|
ItemContainerGenerator.Clear(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
@ -408,12 +408,15 @@ namespace Avalonia.Controls.Primitives |
|
|
|
|
|
|
|
var panel = (InputElement)Presenter.Panel; |
|
|
|
|
|
|
|
foreach (var container in e.Containers) |
|
|
|
if (panel != null) |
|
|
|
{ |
|
|
|
if (KeyboardNavigation.GetTabOnceActiveElement(panel) == container.ContainerControl) |
|
|
|
foreach (var container in e.Containers) |
|
|
|
{ |
|
|
|
KeyboardNavigation.SetTabOnceActiveElement(panel, null); |
|
|
|
break; |
|
|
|
if (KeyboardNavigation.GetTabOnceActiveElement(panel) == container.ContainerControl) |
|
|
|
{ |
|
|
|
KeyboardNavigation.SetTabOnceActiveElement(panel, null); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -247,6 +247,7 @@ namespace Avalonia.Controls.Primitives |
|
|
|
foreach (var child in this.GetTemplateChildren()) |
|
|
|
{ |
|
|
|
child.SetValue(TemplatedParentProperty, null); |
|
|
|
((ISetLogicalParent)child).SetParent(null); |
|
|
|
} |
|
|
|
|
|
|
|
VisualChildren.Clear(); |
|
|
|
|
|
|
|
@ -315,6 +315,26 @@ namespace Avalonia.Controls.UnitTests |
|
|
|
Assert.Same(before, after); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Clear_Containers_When_ItemsPresenter_Changes() |
|
|
|
{ |
|
|
|
var target = new ItemsControl |
|
|
|
{ |
|
|
|
Items = new[] { "foo", "bar" }, |
|
|
|
Template = GetTemplate(), |
|
|
|
}; |
|
|
|
|
|
|
|
target.ApplyTemplate(); |
|
|
|
target.Presenter.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Equal(2, target.ItemContainerGenerator.Containers.Count()); |
|
|
|
|
|
|
|
target.Template = GetTemplate(); |
|
|
|
target.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Empty(target.ItemContainerGenerator.Containers); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Empty_Class_Should_Initially_Be_Applied() |
|
|
|
{ |
|
|
|
|
|
|
|
@ -160,6 +160,24 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
Assert.Equal(target, child.GetLogicalParent()); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Changing_Template_Should_Clear_Old_Templated_Childs_Parent() |
|
|
|
{ |
|
|
|
var target = new TemplatedControl |
|
|
|
{ |
|
|
|
Template = new FuncControlTemplate(_ => new Decorator()) |
|
|
|
}; |
|
|
|
|
|
|
|
target.ApplyTemplate(); |
|
|
|
|
|
|
|
var child = (Decorator)target.GetVisualChildren().Single(); |
|
|
|
|
|
|
|
target.Template = new FuncControlTemplate(_ => new Canvas()); |
|
|
|
target.ApplyTemplate(); |
|
|
|
|
|
|
|
Assert.Null(child.Parent); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Nested_Templated_Control_Should_Not_Have_Template_Applied() |
|
|
|
{ |
|
|
|
|