Browse Source

Added StyleTrigger binding priority.

This allows :mouseover etc to override the value that comes from the
templated parent.
pull/4/head
Steven Kirk 12 years ago
parent
commit
486863f795
  1. 2
      Perspex.UnitTests/Controls/ContentControlTests.cs
  2. 9
      Perspex.UnitTests/Styling/SelectorTests_Class.cs
  3. 9
      Perspex.UnitTests/Styling/SelectorTests_Id.cs
  4. 9
      Perspex.UnitTests/Styling/SelectorTests_OfType.cs
  5. 19
      Perspex/PerspexObject.cs
  6. 16
      Perspex/Styling/Selector.cs
  7. 2
      Perspex/Styling/Selectors.cs
  8. 2
      Perspex/Styling/Style.cs
  9. 4
      Perspex/Themes/Default/ButtonStyle.cs

2
Perspex.UnitTests/Controls/ContentControlTests.cs

@ -74,7 +74,7 @@ namespace Perspex.UnitTests.Controls
contentPresenter.Bind(
ContentPresenter.ContentProperty,
parent.GetObservable(ContentControl.ContentProperty),
BindingPriority.Template);
BindingPriority.TemplatedParent);
border.Content = contentPresenter;
return border;
});

9
Perspex.UnitTests/Styling/SelectorTests_Class.cs

@ -16,6 +16,15 @@ namespace Perspex.UnitTests.Styling
[TestClass]
public class SelectorTests_Class
{
[TestMethod]
public void Class_Priority_Is_StyleTrigger()
{
var control = new Control1();
var target = new Selector().Class("foo");
Assert.AreEqual(BindingPriority.StyleTrigger, target.Priority);
}
[TestMethod]
public void Class_Matches_Control_With_Class()
{

9
Perspex.UnitTests/Styling/SelectorTests_Id.cs

@ -18,6 +18,15 @@ namespace Perspex.UnitTests.Styling
[TestClass]
public class SelectorTests_Id
{
[TestMethod]
public void Id_Priority_Is_Style()
{
var control = new Control1();
var target = new Selector().Id("foo");
Assert.AreEqual(BindingPriority.Style, target.Priority);
}
[TestMethod]
public void Id_Matches_Control_With_Correct_Id()
{

9
Perspex.UnitTests/Styling/SelectorTests_OfType.cs

@ -16,6 +16,15 @@ namespace Perspex.UnitTests.Styling
[TestClass]
public class SelectorTests_OfType
{
[TestMethod]
public void OfType_Priority_Is_Style()
{
var control = new Control1();
var target = new Selector().OfType<Control1>();
Assert.AreEqual(BindingPriority.Style, target.Priority);
}
[TestMethod]
public void OfType_Matches_Control_Of_Correct_Type()
{

19
Perspex/PerspexObject.cs

@ -24,14 +24,25 @@ namespace Perspex
LocalValue,
/// <summary>
/// A style binding.
/// A triggered style binding.
/// </summary>
Style,
/// <remarks>
/// A style trigger is a selector such as .class which overrides a
/// <see cref="TemplatedParent"/> binding. In this way, a basic control can have
/// for example a Background from the templated parent which changes when the
/// control has the :mouseover class.
/// </remarks>
StyleTrigger,
/// <summary>
/// A template binding.
/// A binding to a property on the templated parent.
/// </summary>
Template,
TemplatedParent,
/// <summary>
/// A style binding.
/// </summary>
Style,
}
/// <summary>

16
Perspex/Styling/Selector.cs

@ -20,16 +20,26 @@ namespace Perspex.Styling
public Selector()
{
this.GetObservable = _ => Observable.Return(true);
this.Priority = BindingPriority.Style;
}
public Selector(Selector previous, bool stopTraversal = false)
: this()
{
this.Previous = previous;
this.Priority = previous.Priority;
this.InTemplate = previous != null ? previous.InTemplate : false;
this.stopTraversal = stopTraversal;
}
public Selector(Selector previous, BindingPriority priority)
: this()
{
this.Previous = previous;
this.Priority = priority;
this.InTemplate = previous != null ? previous.InTemplate : false;
}
public bool InTemplate
{
get;
@ -48,6 +58,12 @@ namespace Perspex.Styling
private set;
}
public BindingPriority Priority
{
get;
private set;
}
public string SelectorString
{
get;

2
Perspex/Styling/Selectors.cs

@ -18,7 +18,7 @@ namespace Perspex.Styling
Contract.Requires<ArgumentNullException>(previous != null);
Contract.Requires<ArgumentNullException>(name != null);
return new Selector(previous)
return new Selector(previous, BindingPriority.StyleTrigger)
{
GetObservable = control => Observable
.Return(control.Classes.Contains(name))

2
Perspex/Styling/Style.cs

@ -48,7 +48,7 @@ namespace Perspex.Styling
foreach (Setter setter in this.Setters)
{
StyleBinding binding = new StyleBinding(activator, setter.Value, description);
control.Bind(setter.Property, binding, BindingPriority.Style);
control.Bind(setter.Property, binding, this.Selector.Priority);
}
}
}

4
Perspex/Themes/Default/ButtonStyle.cs

@ -59,13 +59,13 @@ namespace Perspex.Themes.Default
border.Bind(
Border.BackgroundProperty,
control.GetObservable(Button.BackgroundProperty),
BindingPriority.Template);
BindingPriority.TemplatedParent);
ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.Bind(
ContentPresenter.ContentProperty,
control.GetObservable(Button.ContentProperty),
BindingPriority.Template);
BindingPriority.TemplatedParent);
border.Content = contentPresenter;
return border;

Loading…
Cancel
Save