Browse Source

Added ITemplatedControl interface.

pull/4/head
grokys 12 years ago
parent
commit
6fd6f186ec
  1. 1
      Perspex.UnitTests/Perspex.UnitTests.csproj
  2. 6
      Perspex.UnitTests/Styling/SelectorTests_Id.cs
  3. 12
      Perspex.UnitTests/Styling/SelectorTests_InTemplateOf.cs
  4. 34
      Perspex.UnitTests/Styling/SelectorTests_Template.cs
  5. 2
      Perspex.UnitTests/Styling/SubscribeCheck.cs
  6. 10
      Perspex/ControlTemplate.cs
  7. 2
      Perspex/Controls/Control.cs
  8. 12
      Perspex/Controls/ITemplatedControl.cs
  9. 2
      Perspex/Controls/TemplatedControl.cs
  10. 1
      Perspex/Perspex.csproj
  11. 2
      Perspex/Styling/IStyleable.cs
  12. 2
      Perspex/Styling/Selectors.cs

1
Perspex.UnitTests/Perspex.UnitTests.csproj

@ -69,6 +69,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PerspexObjectTests.cs" />
<Compile Include="StyleTests.cs" />
<Compile Include="Styling\SelectorTests_Template.cs" />
<Compile Include="Styling\SelectorTests_Class.cs" />
<Compile Include="Styling\SelectorTests_Id.cs" />
<Compile Include="Styling\SelectorTests_OfType.cs" />

6
Perspex.UnitTests/Styling/SelectorTests_Id.cs

@ -78,12 +78,8 @@ namespace Perspex.UnitTests.Styling
{
}
public class TemplatedControl1 : TemplatedControl
public class TemplatedControl1 : ITemplatedControl
{
protected override Size MeasureContent(Size availableSize)
{
throw new NotImplementedException();
}
}
}
}

12
Perspex.UnitTests/Styling/SelectorTests_InTemplateOf.cs

@ -60,20 +60,12 @@ namespace Perspex.UnitTests.Styling
{
}
public class TemplatedControl1 : TemplatedControl
public class TemplatedControl1 : ITemplatedControl
{
protected override Size MeasureContent(Size availableSize)
{
throw new NotImplementedException();
}
}
public class TemplatedControl2 : TemplatedControl
public class TemplatedControl2 : ITemplatedControl
{
protected override Size MeasureContent(Size availableSize)
{
throw new NotImplementedException();
}
}
}
}

34
Perspex.UnitTests/Styling/SelectorTests_Template.cs

@ -0,0 +1,34 @@
// -----------------------------------------------------------------------
// <copyright file="SelectorTests.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.UnitTests.Styling
{
using System.Linq;
using System.Reactive.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Perspex.Styling;
[TestClass]
public class SelectorTests_Template
{
[TestMethod]
public void Foo()
{
var control = new Control1
{
Classes = new Classes { "foo" },
};
var target = control.Select().Class("foo");
CollectionAssert.AreEqual(new[] { true }, target.GetActivator().Take(1).ToEnumerable().ToArray());
}
public class Control1 : SubscribeCheck
{
}
}
}

2
Perspex.UnitTests/Styling/SubscribeCheck.cs

@ -38,7 +38,7 @@ namespace Perspex.UnitTests.Styling
public TestObservable SubscribeCheckObservable { get; private set; }
public TemplatedControl TemplatedParent
public ITemplatedControl TemplatedParent
{
get;
set;

10
Perspex/ControlTemplate.cs

@ -13,16 +13,16 @@ namespace Perspex
public class ControlTemplate
{
private Func<TemplatedControl, Control> build;
private Func<ITemplatedControl, Control> build;
public ControlTemplate(Func<TemplatedControl, Control> build)
public ControlTemplate(Func<ITemplatedControl, Control> build)
{
Contract.Requires<NullReferenceException>(build != null);
this.build = build;
}
public Control Build(TemplatedControl templatedParent)
public Control Build(ITemplatedControl templatedParent)
{
Contract.Requires<NullReferenceException>(templatedParent != null);
@ -32,14 +32,14 @@ namespace Perspex
}
public static ControlTemplate Create<TControl>(Func<TControl, Control> build)
where TControl : TemplatedControl
where TControl : ITemplatedControl
{
Contract.Requires<NullReferenceException>(build != null);
return new ControlTemplate(c => build((TControl)c));
}
private void SetTemplatedParent(Control control, TemplatedControl templatedParent)
private void SetTemplatedParent(Control control, ITemplatedControl templatedParent)
{
Contract.Requires<NullReferenceException>(control != null);
Contract.Requires<NullReferenceException>(templatedParent != null);

2
Perspex/Controls/Control.cs

@ -218,7 +218,7 @@ namespace Perspex.Controls
}
}
public TemplatedControl TemplatedParent
public ITemplatedControl TemplatedParent
{
get;
internal set;

12
Perspex/Controls/ITemplatedControl.cs

@ -0,0 +1,12 @@
// -----------------------------------------------------------------------
// <copyright file="ITemplatedControl.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.Controls
{
public interface ITemplatedControl
{
}
}

2
Perspex/Controls/TemplatedControl.cs

@ -11,7 +11,7 @@ namespace Perspex.Controls
using System.Linq;
using Perspex.Media;
public abstract class TemplatedControl : Control
public abstract class TemplatedControl : Control, ITemplatedControl
{
public static readonly PerspexProperty<ControlTemplate> TemplateProperty =
PerspexProperty.Register<TemplatedControl, ControlTemplate>("Template");

1
Perspex/Perspex.csproj

@ -76,6 +76,7 @@
<Compile Include="Controls\Decorator.cs" />
<Compile Include="Controls\ContentControl.cs" />
<Compile Include="Controls\Control.cs" />
<Compile Include="Controls\ITemplatedControl.cs" />
<Compile Include="Controls\TextBlock.cs" />
<Compile Include="ControlTemplate.cs" />
<Compile Include="Input\MouseEventArgs.cs" />

2
Perspex/Styling/IStyleable.cs

@ -27,7 +27,7 @@ namespace Perspex.Styling
/// <summary>
/// Gets the template parent of this element if the control comes from a template.
/// </summary>
TemplatedControl TemplatedParent { get; }
ITemplatedControl TemplatedParent { get; }
/// <summary>
/// Binds a <see cref="PerspexProperty"/> to a style.

2
Perspex/Styling/Selectors.cs

@ -54,7 +54,7 @@ namespace Perspex.Styling
return match;
}
public static Match InTemplateOf<T>(this Match match) where T : TemplatedControl
public static Match InTemplateOf<T>(this Match match) where T : ITemplatedControl
{
Contract.Requires<ArgumentNullException>(match != null);

Loading…
Cancel
Save