Browse Source

Added failing test for #2191.

Check that when content is created via `DataTemplate`, it is correctly added as a logical child.
pull/2218/head
Steven Kirk 8 years ago
parent
commit
792d9f1a05
  1. 50
      tests/Avalonia.Controls.UnitTests/TabControlTests.cs

50
tests/Avalonia.Controls.UnitTests/TabControlTests.cs

@ -267,26 +267,46 @@ namespace Avalonia.Controls.UnitTests
Assert.Null(page.Content);
}
[Fact]
public void DataTemplate_Created_Content_Should_Be_Logical_Child_After_ApplyTemplate()
{
TabControl target = new TabControl
{
Template = TabControlTemplate(),
ContentTemplate = new FuncDataTemplate<string>(x =>
new TextBlock { Tag = "bar", Text = x }),
Items = new[] { "Foo" },
};
ApplyTemplate(target);
target.ContentPart.UpdateChild();
var content = Assert.IsType<TextBlock>(target.ContentPart.Child);
Assert.Equal("bar", content.Tag);
Assert.Same(target, content.GetLogicalParent());
Assert.Single(target.GetLogicalChildren(), content);
}
private IControlTemplate TabControlTemplate()
{
return new FuncControlTemplate<TabControl>(parent =>
new StackPanel
{
Children = {
new ItemsPresenter
{
Name = "PART_ItemsPresenter",
[!TabStrip.ItemsProperty] = parent[!TabControl.ItemsProperty],
[!TabStrip.ItemTemplateProperty] = parent[!TabControl.ItemTemplateProperty],
},
new ContentPresenter
{
Name = "PART_Content",
[!ContentPresenter.ContentProperty] = parent[!TabControl.SelectedContentProperty],
[!ContentPresenter.ContentTemplateProperty] = parent[!TabControl.SelectedContentTemplateProperty],
}
}
Children =
{
new ItemsPresenter
{
Name = "PART_ItemsPresenter",
[!TabStrip.ItemsProperty] = parent[!TabControl.ItemsProperty],
[!TabStrip.ItemTemplateProperty] = parent[!TabControl.ItemTemplateProperty],
},
new ContentPresenter
{
Name = "PART_Content",
[!ContentPresenter.ContentProperty] = parent[!TabControl.SelectedContentProperty],
[!ContentPresenter.ContentTemplateProperty] = parent[!TabControl.SelectedContentTemplateProperty],
}
}
});
}

Loading…
Cancel
Save