Browse Source

Fix TabControl logical parent.

pull/58/head
Steven Kirk 12 years ago
parent
commit
04673d539f
  1. 2
      Perspex.Controls/Control.cs
  2. 5
      Perspex.Controls/Deck.cs
  3. 13
      Perspex.Controls/INamed.cs
  4. 4
      Perspex.Controls/ItemsControl.cs
  5. 2
      Perspex.Controls/Perspex.Controls.csproj
  6. 2
      Perspex.Controls/Presenters/DeckPresenter.cs
  7. 13
      Perspex.Controls/Presenters/IItemsPresenter.cs
  8. 2
      Perspex.Controls/Presenters/IPresenter.cs
  9. 2
      Perspex.Controls/Presenters/ItemsPresenter.cs
  10. 4
      Perspex.Controls/Templates/TemplateExtensions.cs
  11. 2
      Tests/Perspex.Base.UnitTests/PerspexObjectTests.cs
  12. 68
      Tests/Perspex.Controls.UnitTests/DeckTests.cs
  13. 1
      Tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj

2
Perspex.Controls/Control.cs

@ -20,7 +20,7 @@ namespace Perspex.Controls
using Perspex.Styling;
using Splat;
public class Control : InputElement, ILogical, IStyleable, IStyleHost
public class Control : InputElement, INamed, ILogical, IStyleable, IStyleHost
{
public static readonly PerspexProperty<object> DataContextProperty =
PerspexProperty.Register<Control, object>("DataContext", inherits: true);

5
Perspex.Controls/Deck.cs

@ -56,5 +56,10 @@ namespace Perspex.Controls
{
// Ignore pointer presses.
}
protected override void OnTemplateApplied()
{
base.OnTemplateApplied();
}
}
}

13
Perspex.Controls/INamed.cs

@ -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; }
}
}

4
Perspex.Controls/ItemsControl.cs

@ -83,7 +83,7 @@ namespace Perspex.Controls
}
}
protected ItemsPresenter Presenter
protected IItemsPresenter Presenter
{
get;
private set;
@ -96,7 +96,7 @@ namespace Perspex.Controls
protected override void OnTemplateApplied()
{
this.Presenter = this.FindTemplateChild<ItemsPresenter>("itemsPresenter");
this.Presenter = this.FindTemplateChild<IItemsPresenter>("itemsPresenter");
if (this.Presenter != null)
{

2
Perspex.Controls/Perspex.Controls.csproj

@ -42,12 +42,14 @@
<Compile Include="DropDown.cs" />
<Compile Include="IContentControl.cs" />
<Compile Include="IItemsPanel.cs" />
<Compile Include="INamed.cs" />
<Compile Include="INavigablePanel.cs" />
<Compile Include="Deck.cs" />
<Compile Include="Platform\IPopupImpl.cs" />
<Compile Include="Platform\ITopLevelImpl.cs" />
<Compile Include="Popup.cs" />
<Compile Include="IDataTemplate.cs" />
<Compile Include="Presenters\IItemsPresenter.cs" />
<Compile Include="Presenters\IPresenter.cs" />
<Compile Include="Presenters\DeckPresenter.cs" />
<Compile Include="Primitives\AdornerDecorator.cs" />

2
Perspex.Controls/Presenters/DeckPresenter.cs

@ -17,7 +17,7 @@ namespace Perspex.Controls.Presenters
using System.Linq;
using System.Reactive.Linq;
public class DeckPresenter : Control, IVisual, IPresenter, ITemplatedControl
public class DeckPresenter : Control, IItemsPresenter, ITemplatedControl
{
public static readonly PerspexProperty<IEnumerable> ItemsProperty =
ItemsControl.ItemsProperty.AddOwner<DeckPresenter>();

13
Perspex.Controls/Presenters/IItemsPresenter.cs

@ -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; }
}
}

2
Perspex.Controls/Presenters/IPresenter.cs

@ -18,7 +18,7 @@ namespace Perspex.Controls.Presenters
/// of a <see cref="TemplatedControl"/> then that signals that the visual child
/// of the presenter is not a part of the template.
/// </remarks>
public interface IPresenter : IVisual
public interface IPresenter : IVisual, INamed
{
}
}

2
Perspex.Controls/Presenters/ItemsPresenter.cs

@ -14,7 +14,7 @@ namespace Perspex.Controls.Presenters
using System.Collections.Specialized;
using System.Reactive.Linq;
public class ItemsPresenter : Control, IVisual, IPresenter, ITemplatedControl
public class ItemsPresenter : Control, IItemsPresenter, ITemplatedControl
{
public static readonly PerspexProperty<IEnumerable> ItemsProperty =
ItemsControl.ItemsProperty.AddOwner<ItemsPresenter>();

4
Perspex.Controls/Templates/TemplateExtensions.cs

@ -15,12 +15,12 @@ namespace Perspex.Controls.Templates
public static class TemplateExtensions
{
public static T FindTemplateChild<T>(this ITemplatedControl control, string id) where T : Control
public static T FindTemplateChild<T>(this ITemplatedControl control, string id) where T : INamed
{
return control.GetTemplateChildren().OfType<T>().SingleOrDefault(x => x.Id == id);
}
public static T GetTemplateChild<T>(this ITemplatedControl control, string id) where T : Control
public static T GetTemplateChild<T>(this ITemplatedControl control, string id) where T : INamed
{
var result = control.FindTemplateChild<T>(id);

2
Tests/Perspex.Base.UnitTests/PerspexObjectTests.cs

@ -35,7 +35,7 @@ namespace Perspex.Base.UnitTests
{
string[] names = PerspexObject.GetProperties(typeof(Class2)).Select(x => x.Name).ToArray();
Assert.Equal(new[] { "Bar", "Foo", "Baz", "Qux" }, names);
Assert.Equal(new[] { "Bar", "Flob", "Foo", "Baz", "Qux" }, names);
}
[Fact]

68
Tests/Perspex.Controls.UnitTests/DeckTests.cs

@ -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],
};
}
}
}

1
Tests/Perspex.Controls.UnitTests/Perspex.Controls.UnitTests.csproj

@ -99,6 +99,7 @@
<Compile Include="ItemsControlTests.cs" />
<Compile Include="ContentControlTests.cs" />
<Compile Include="DecoratorTests.cs" />
<Compile Include="DeckTests.cs" />
<Compile Include="TabStripTests.cs" />
<Compile Include="TabControlTests.cs" />
<Compile Include="PanelTests.cs" />

Loading…
Cancel
Save