Browse Source

Another tweak to the binding system.

Binding levels with a an even number priority use the last fired binding
for the current value, those with odd number priorities use the latest
added.
pull/58/head
Steven Kirk 11 years ago
parent
commit
df77302d94
  1. 7
      Perspex.Base/PerspexObject.cs
  2. 22
      Perspex.Base/PriorityLevel.cs
  3. 5
      Perspex.Base/PriorityValue.cs
  4. 5
      Perspex.Themes.Default/DropDownStyle.cs

7
Perspex.Base/PerspexObject.cs

@ -6,6 +6,7 @@
namespace Perspex
{
using Perspex.Reactive;
using Splat;
using System;
using System.Collections.Generic;
@ -14,8 +15,6 @@ namespace Perspex
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reflection;
using Perspex.Diagnostics;
using Perspex.Reactive;
/// <summary>
/// The priority of a binding.
@ -25,12 +24,12 @@ namespace Perspex
/// <summary>
/// A value that comes from an animation.
/// </summary>
Animation = -1,
Animation = -2,
/// <summary>
/// A local value.
/// </summary>
LocalValue,
LocalValue = 0,
/// <summary>
/// A triggered style binding.

22
Perspex.Base/PriorityLevel.cs

@ -10,6 +10,22 @@ namespace Perspex
using System.Collections.Generic;
using System.Reactive.Disposables;
/// <summary>
/// Determines how the current binding is selected for a <see cref="PriorityLevel"/>.
/// </summary>
internal enum LevelPrecedenceMode
{
/// <summary>
/// The latest fired binding is used as the current value.
/// </summary>
Latest,
/// <summary>
/// The latest added binding is used as the current value.
/// </summary>
Newest,
}
/// <summary>
/// Stores bindings for a priority level in a <see cref="PriorityValue"/>.
/// </summary>
@ -49,6 +65,8 @@ namespace Perspex
/// </summary>
private int nextIndex;
private LevelPrecedenceMode mode;
/// <summary>
/// Initializes a new instance of the <see cref="PriorityLevel"/> class.
/// </summary>
@ -56,10 +74,12 @@ namespace Perspex
/// <param name="changed">A method to be called when the current value changes.</param>
public PriorityLevel(
int priority,
LevelPrecedenceMode mode,
Action<PriorityLevel> changed)
{
Contract.Requires<ArgumentNullException>(changed != null);
this.mode = mode;
this.changed = changed;
this.Priority = priority;
this.Value = this.directValue = PerspexProperty.UnsetValue;
@ -136,7 +156,7 @@ namespace Perspex
/// <param name="entry">The entry that changed.</param>
private void Changed(PriorityBindingEntry entry)
{
if (entry.Index >= this.ActiveBindingIndex)
if (mode == LevelPrecedenceMode.Latest || entry.Index >= this.ActiveBindingIndex)
{
if (entry.Value != PerspexProperty.UnsetValue)
{

5
Perspex.Base/PriorityValue.cs

@ -195,7 +195,7 @@ namespace Perspex
b.AppendLine(level.Value.Value?.ToString() ?? "(null)");
b.AppendLine("--------");
b.Append("Direct: ");
b.AppendLine(level.Value.DirectValue.ToString());
b.AppendLine(level.Value.DirectValue?.ToString() ?? "(null)");
foreach (var binding in level.Value.Bindings)
{
@ -239,7 +239,8 @@ namespace Perspex
if (!this.levels.TryGetValue(priority, out result))
{
result = new PriorityLevel(priority, this.ValueChanged);
var mode = (LevelPrecedenceMode)(priority % 2);
result = new PriorityLevel(priority, mode, this.ValueChanged);
this.levels.Add(priority, result);
}

5
Perspex.Themes.Default/DropDownStyle.cs

@ -98,9 +98,8 @@ namespace Perspex.Themes.Default
},
PlacementTarget = control,
StaysOpen = false,
[!Popup.IsOpenProperty] = control[!DropDown.IsDropDownOpenProperty],
[~Popup.MinWidthProperty] = control[~DropDown.BoundsProperty].Cast<Rect>().Select(x => (object)x.Width),
}
[~~Popup.IsOpenProperty] = control[~~DropDown.IsDropDownOpenProperty],
[~Popup.MinWidthProperty] = control[~DropDown.BoundsProperty].Cast<Rect>().Select(x => (object)x.Width), }
},
},
};

Loading…
Cancel
Save