Browse Source

Handle null content in TabControl.

pull/390/head
Steven Kirk 11 years ago
parent
commit
7adc902b99
  1. 2
      src/Perspex.Controls/ItemsControl.cs
  2. 8
      src/Perspex.Controls/Primitives/SelectingItemsControl.cs
  3. 24
      tests/Perspex.Controls.UnitTests/TabControlTests.cs

2
src/Perspex.Controls/ItemsControl.cs

@ -218,7 +218,7 @@ namespace Perspex.Controls
{
// If the item is its own container, then it will be added to the logical tree when
// it was added to the Items collection.
if (container.ContainerControl != container.Item)
if (container.ContainerControl != null && container.ContainerControl != container.Item)
{
toAdd.Add(container.ContainerControl);
}

8
src/Perspex.Controls/Primitives/SelectingItemsControl.cs

@ -323,7 +323,11 @@ namespace Perspex.Controls.Primitives
selectedIndex < e.StartingIndex + e.Containers.Count)
{
var container = e.Containers[selectedIndex - e.StartingIndex];
MarkContainerSelected(container.ContainerControl, true);
if (container.ContainerControl != null)
{
MarkContainerSelected(container.ContainerControl, true);
}
}
}
@ -656,7 +660,7 @@ namespace Perspex.Controls.Primitives
foreach (var item in generator.Containers)
{
if (item != null)
if (item?.ContainerControl != null)
{
if (MarkContainerSelected(item.ContainerControl, false))
{

24
tests/Perspex.Controls.UnitTests/TabControlTests.cs

@ -239,6 +239,30 @@ namespace Perspex.Controls.UnitTests
Assert.Equal(new object[] { string.Empty, string.Empty }, result);
}
[Fact]
public void Should_Handle_Changing_To_TabItem_With_Null_Content()
{
TabControl target = new TabControl
{
Template = new FuncControlTemplate<TabControl>(CreateTabControlTemplate),
Items = new[]
{
new TabItem { Header = "Foo" },
new TabItem { Header = "Foo", Content = new Decorator() },
new TabItem { Header = "Baz" },
},
};
ApplyTemplate(target);
target.SelectedIndex = 2;
var carousel = (Carousel)target.Pages;
var page = (TabItem)carousel.SelectedItem;
Assert.Null(page.Content);
}
private Control CreateTabControlTemplate(TabControl parent)
{
return new StackPanel

Loading…
Cancel
Save