Browse Source

Fixed failing tests.

pull/58/head
Steven Kirk 11 years ago
parent
commit
7f608ffa6c
  1. 4
      Perspex.Base/Collections/PerspexReadOnlyListView.cs
  2. 15
      Perspex.Controls/Generators/ItemContainerGenerator.cs
  3. 10
      Perspex.Controls/Presenters/DeckPresenter.cs
  4. 3
      Perspex.Controls/Primitives/TabStrip.cs
  5. 9
      Perspex.Controls/TabControl.cs
  6. 4
      Perspex.Themes.Default/TabControlStyle.cs
  7. 69
      Tests/Perspex.Controls.UnitTests/TabControlTests.cs

4
Perspex.Base/Collections/PerspexReadOnlyListView.cs

@ -38,7 +38,7 @@ namespace Perspex.Collections
public int Count
{
get { return this.source.Count; }
get { return this.source?.Count ?? 0; }
}
public IPerspexReadOnlyList<T> Source
@ -169,7 +169,7 @@ namespace Perspex.Collections
public int Count
{
get { return this.source.Count; }
get { return this.source?.Count ?? 0; }
}
public IPerspexReadOnlyList<TIn> Source

15
Perspex.Controls/Generators/ItemContainerGenerator.cs

@ -85,14 +85,17 @@ namespace Perspex.Controls.Generators
{
Control container = this.CreateContainerOverride(item);
if (container.DataContext == null)
if (container != null)
{
container.DataContext = item;
if (container.DataContext == null)
{
container.DataContext = item;
}
container.TemplatedParent = null;
this.AddInternal(item, container);
result.Add(container);
}
container.TemplatedParent = null;
this.AddInternal(item, container);
result.Add(container);
}
}
finally

10
Perspex.Controls/Presenters/DeckPresenter.cs

@ -135,9 +135,13 @@ namespace Perspex.Controls.Presenters
if (value.Item2 != null)
{
to = generator.Generate(new[] { value.Item2 }).Single();
this.Panel.Children.Add(to);
toIndex = this.Items.IndexOf(value.Item2);
to = generator.Generate(new[] { value.Item2 }).FirstOrDefault();
if (to != null)
{
this.Panel.Children.Add(to);
toIndex = this.Items.IndexOf(value.Item2);
}
}
if (this.Transition != null)

3
Perspex.Controls/Primitives/TabStrip.cs

@ -27,7 +27,8 @@ namespace Perspex.Controls.Primitives
public TabStrip()
{
this.BindTwoWay(SelectedTabProperty, this, SelectingItemsControl.SelectedItemProperty);
this.GetObservable(SelectedItemProperty).Subscribe(x => this.SelectedTab = x as TabItem);
this.GetObservable(SelectedTabProperty).Subscribe(x => this.SelectedItem = x as TabItem);
}
public TabItem SelectedTab

9
Perspex.Controls/TabControl.cs

@ -35,14 +35,15 @@ namespace Perspex.Controls
public TabControl()
{
this.BindTwoWay(SelectedTabProperty, this, SelectingItemsControl.SelectedItemProperty);
this.GetObservable(SelectedItemProperty).Subscribe(x =>
{
ContentControl c = x as ContentControl;
object content = (c != null) ? c.Content : c;
this.SetValue(SelectedTabProperty, x);
this.SetValue(SelectedContentProperty, content);
});
this.BindTwoWay(SelectedTabProperty, this, SelectingItemsControl.SelectedItemProperty);
}
public object SelectedContent
@ -73,11 +74,13 @@ namespace Perspex.Controls
// Don't handle keypresses.
}
Deck deck;
protected override void OnTemplateApplied()
{
base.OnTemplateApplied();
var deck = this.GetTemplateChild<Deck>("deck");
this.deck = this.GetTemplateChild<Deck>("deck");
this.logicalChildren.Source = ((ILogical)deck).LogicalChildren;
}
}

4
Perspex.Themes.Default/TabControlStyle.cs

@ -47,7 +47,7 @@ namespace Perspex.Themes.Default
{
Name = "tabStrip",
[~TabStrip.ItemsProperty] = control[~TabControl.ItemsProperty],
[~~TabStrip.SelectedItemProperty] = control[~~TabControl.SelectedItemProperty],
[!!TabStrip.SelectedItemProperty] = control[!!TabControl.SelectedItemProperty],
},
new Deck
{
@ -57,7 +57,7 @@ namespace Perspex.Themes.Default
new DataTemplate<TabItem>(x => control.MaterializeDataTemplate(x.Content)),
},
[~Deck.ItemsProperty] = control[~TabControl.ItemsProperty],
[!Deck.SelectedItemProperty] = control[!TabControl.SelectedItemProperty],
[~Deck.SelectedItemProperty] = control[~TabControl.SelectedItemProperty],
[~Deck.TransitionProperty] = control[~TabControl.TransitionProperty],
[Grid.RowProperty] = 1,
}

69
Tests/Perspex.Controls.UnitTests/TabControlTests.cs

@ -6,11 +6,11 @@
namespace Perspex.Controls.UnitTests
{
using System.Linq;
using Perspex.Controls.Presenters;
using Perspex.Controls.Primitives;
using Perspex.Controls.Templates;
using Perspex.LogicalTree;
using Perspex.Styling;
using System.Linq;
using Xunit;
public class TabControlTests
@ -18,50 +18,30 @@ namespace Perspex.Controls.UnitTests
[Fact]
public void First_Tab_Should_Be_Selected_By_Default()
{
TabItem selected;
var target = new TabControl
{
Template = ControlTemplate.Create<TabControl>(this.CreateTabControlTemplate),
Items = new[]
{
new TabItem
{
Name = "first"
},
new TabItem
{
Name = "second"
},
}
};
target.ApplyTemplate();
Assert.NotNull(target.SelectedTab);
Assert.Equal(target.SelectedTab, target.SelectedItem);
}
[Fact]
public void First_Tab_Content_Should_Be_Displayed_By_Default()
{
var target = new TabControl
{
Template = ControlTemplate.Create<TabControl>(this.CreateTabControlTemplate),
Items = new[]
{
new TabItem
(selected = new TabItem
{
Content = new TextBlock(),
},
Name = "first",
Content = "foo",
}),
new TabItem
{
Content = new Border(),
Name = "second",
Content = "bar",
},
}
};
target.ApplyTemplate();
Assert.IsType<TextBlock>(target.SelectedContent);
Assert.Equal(selected, target.SelectedItem);
Assert.Equal(selected, target.SelectedTab);
Assert.Equal("foo", target.SelectedContent);
}
[Fact]
@ -124,11 +104,11 @@ namespace Perspex.Controls.UnitTests
{
new TabItem
{
Content = new TextBlock { Name = "Foo" }
Content = "foo"
},
new TabItem
{
Content = new TextBlock { Name = "Foo" }
Content = "bar"
},
},
};
@ -136,7 +116,7 @@ namespace Perspex.Controls.UnitTests
target.ApplyTemplate();
Assert.Equal(1, target.GetLogicalChildren().Count());
Assert.Equal("Foo", ((TextBlock)target.GetLogicalChildren().First()).Name);
Assert.Equal("foo", ((TextBlock)target.GetLogicalChildren().First()).Text);
}
private Control CreateTabControlTemplate(TabControl parent)
@ -155,8 +135,13 @@ namespace Perspex.Controls.UnitTests
new Deck
{
Name = "deck",
Template = ControlTemplate.Create<Deck>(this.CreateDeckTemplate),
DataTemplates = new DataTemplates
{
new DataTemplate<TabItem>(x => parent.MaterializeDataTemplate(x.Content)),
},
[~Deck.ItemsProperty] = parent[~TabControl.ItemsProperty],
[!Deck.SelectedItemProperty] = parent[!TabControl.SelectedItemProperty],
[~Deck.SelectedItemProperty] = parent[~TabControl.SelectedItemProperty],
}
}
};
@ -170,5 +155,17 @@ namespace Perspex.Controls.UnitTests
[~ItemsPresenter.ItemsProperty] = parent[~TabStrip.ItemsProperty],
};
}
private Control CreateDeckTemplate(Deck control)
{
return new DeckPresenter
{
Name = "itemsPresenter",
[~ItemsPresenter.ItemsProperty] = control[~Deck.ItemsProperty],
[~ItemsPresenter.ItemsPanelProperty] = control[~Deck.ItemsPanelProperty],
[~DeckPresenter.SelectedItemProperty] = control[~Deck.SelectedItemProperty],
[~DeckPresenter.TransitionProperty] = control[~Deck.TransitionProperty],
};
}
}
}

Loading…
Cancel
Save