13 changed files with 111 additions and 9 deletions
@ -0,0 +1,13 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="TemplateExtensions.cs" company="Steven Kirk">
|
||||
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Controls |
||||
|
{ |
||||
|
public interface INamed |
||||
|
{ |
||||
|
string Id { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,13 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="IPresenter.cs" company="Steven Kirk">
|
||||
|
// Copyright 2014 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Controls.Presenters |
||||
|
{ |
||||
|
public interface IItemsPresenter : IPresenter |
||||
|
{ |
||||
|
Panel Panel { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
// -----------------------------------------------------------------------
|
||||
|
// <copyright file="DeckTests.cs" company="Steven Kirk">
|
||||
|
// Copyright 2015 MIT Licence. See licence.md for more information.
|
||||
|
// </copyright>
|
||||
|
// -----------------------------------------------------------------------
|
||||
|
|
||||
|
namespace Perspex.Controls.UnitTests |
||||
|
{ |
||||
|
using Perspex.Controls.Presenters; |
||||
|
using Perspex.LogicalTree; |
||||
|
using System.Linq; |
||||
|
using Xunit; |
||||
|
|
||||
|
public class DeckTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void First_Item_Should_Be_Selected_By_Default() |
||||
|
{ |
||||
|
var target = new Deck |
||||
|
{ |
||||
|
Template = ControlTemplate.Create<Deck>(this.CreateTemplate), |
||||
|
Items = new[] |
||||
|
{ |
||||
|
"Foo", |
||||
|
"Bar" |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
target.ApplyTemplate(); |
||||
|
|
||||
|
Assert.Equal("Foo", target.SelectedItem); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void LogicalChild_Should_Be_Selected_Item() |
||||
|
{ |
||||
|
var target = new Deck |
||||
|
{ |
||||
|
Template = ControlTemplate.Create<Deck>(this.CreateTemplate), |
||||
|
Items = new[] |
||||
|
{ |
||||
|
"Foo", |
||||
|
"Bar" |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
target.ApplyTemplate(); |
||||
|
|
||||
|
Assert.Equal(1, target.GetLogicalChildren().Count()); |
||||
|
|
||||
|
var child = target.GetLogicalChildren().Single(); |
||||
|
Assert.IsType<TextBlock>(child); |
||||
|
Assert.Equal("Foo", ((TextBlock)child).Text); |
||||
|
} |
||||
|
|
||||
|
private Control CreateTemplate(Deck control) |
||||
|
{ |
||||
|
return new DeckPresenter |
||||
|
{ |
||||
|
Id = "itemsPresenter", |
||||
|
[~ItemsPresenter.ItemsProperty] = control[~Deck.ItemsProperty], |
||||
|
[~ItemsPresenter.ItemsPanelProperty] = control[~Deck.ItemsPanelProperty], |
||||
|
[~DeckPresenter.SelectedItemProperty] = control[~Deck.SelectedItemProperty], |
||||
|
[~DeckPresenter.TransitionProperty] = control[~Deck.TransitionProperty], |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue