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

22
Perspex.Base/PriorityLevel.cs

@ -10,6 +10,22 @@ namespace Perspex
using System.Collections.Generic; using System.Collections.Generic;
using System.Reactive.Disposables; 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> /// <summary>
/// Stores bindings for a priority level in a <see cref="PriorityValue"/>. /// Stores bindings for a priority level in a <see cref="PriorityValue"/>.
/// </summary> /// </summary>
@ -49,6 +65,8 @@ namespace Perspex
/// </summary> /// </summary>
private int nextIndex; private int nextIndex;
private LevelPrecedenceMode mode;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PriorityLevel"/> class. /// Initializes a new instance of the <see cref="PriorityLevel"/> class.
/// </summary> /// </summary>
@ -56,10 +74,12 @@ namespace Perspex
/// <param name="changed">A method to be called when the current value changes.</param> /// <param name="changed">A method to be called when the current value changes.</param>
public PriorityLevel( public PriorityLevel(
int priority, int priority,
LevelPrecedenceMode mode,
Action<PriorityLevel> changed) Action<PriorityLevel> changed)
{ {
Contract.Requires<ArgumentNullException>(changed != null); Contract.Requires<ArgumentNullException>(changed != null);
this.mode = mode;
this.changed = changed; this.changed = changed;
this.Priority = priority; this.Priority = priority;
this.Value = this.directValue = PerspexProperty.UnsetValue; this.Value = this.directValue = PerspexProperty.UnsetValue;
@ -136,7 +156,7 @@ namespace Perspex
/// <param name="entry">The entry that changed.</param> /// <param name="entry">The entry that changed.</param>
private void Changed(PriorityBindingEntry entry) private void Changed(PriorityBindingEntry entry)
{ {
if (entry.Index >= this.ActiveBindingIndex) if (mode == LevelPrecedenceMode.Latest || entry.Index >= this.ActiveBindingIndex)
{ {
if (entry.Value != PerspexProperty.UnsetValue) 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(level.Value.Value?.ToString() ?? "(null)");
b.AppendLine("--------"); b.AppendLine("--------");
b.Append("Direct: "); b.Append("Direct: ");
b.AppendLine(level.Value.DirectValue.ToString()); b.AppendLine(level.Value.DirectValue?.ToString() ?? "(null)");
foreach (var binding in level.Value.Bindings) foreach (var binding in level.Value.Bindings)
{ {
@ -239,7 +239,8 @@ namespace Perspex
if (!this.levels.TryGetValue(priority, out result)) 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); this.levels.Add(priority, result);
} }

5
Perspex.Themes.Default/DropDownStyle.cs

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

Loading…
Cancel
Save