using Avalonia.Controls; using Avalonia.Controls.Presenters; using Avalonia.Media; using Avalonia.UnitTests; using Avalonia.VisualTree; using Xunit; namespace Avalonia.Markup.Xaml.UnitTests.Xaml; public class ItemsPanelTemplateTests : XamlTestBase { [Fact] public void ItemsPanelTemplate_In_Style_Allows_TemplateBinding() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var window = (Window)AvaloniaRuntimeXamlLoader.Load( """ """); var listBox = Assert.IsType(window.Content); var items = new[] { "foo", "bar" }; listBox.ItemsSource = items; window.ApplyTemplate(); listBox.ApplyTemplate(); var itemsPresenter = listBox.FindDescendantOfType(); Assert.NotNull(itemsPresenter); itemsPresenter.ApplyTemplate(); var panel = itemsPresenter.Panel; Assert.NotNull(panel); Assert.Equal(Brushes.DodgerBlue, panel.Background); Assert.Same(items, panel.Tag); } } [Fact] public void ItemsPanelTemplate_In_Control_Allows_TemplateBinding() { using (UnitTestApplication.Start(TestServices.StyledWindow)) { var window = (Window)AvaloniaRuntimeXamlLoader.Load( """ """); var listBox = Assert.IsType(window.Content); var items = new[] { "foo", "bar" }; listBox.ItemsSource = items; window.ApplyTemplate(); listBox.ApplyTemplate(); var itemsPresenter = listBox.FindDescendantOfType(); Assert.NotNull(itemsPresenter); itemsPresenter.ApplyTemplate(); var panel = itemsPresenter.Panel; Assert.NotNull(panel); Assert.Equal(Brushes.DodgerBlue, panel.Background); Assert.Same(items, panel.Tag); } } }