From df77302d94d16bd3f174148363f4344b5fd901cd Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Fri, 8 May 2015 20:06:59 +0200 Subject: [PATCH] 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. --- Perspex.Base/PerspexObject.cs | 7 +++---- Perspex.Base/PriorityLevel.cs | 22 +++++++++++++++++++++- Perspex.Base/PriorityValue.cs | 5 +++-- Perspex.Themes.Default/DropDownStyle.cs | 5 ++--- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Perspex.Base/PerspexObject.cs b/Perspex.Base/PerspexObject.cs index 04a369c84b..f749c320b3 100644 --- a/Perspex.Base/PerspexObject.cs +++ b/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; /// /// The priority of a binding. @@ -25,12 +24,12 @@ namespace Perspex /// /// A value that comes from an animation. /// - Animation = -1, + Animation = -2, /// /// A local value. /// - LocalValue, + LocalValue = 0, /// /// A triggered style binding. diff --git a/Perspex.Base/PriorityLevel.cs b/Perspex.Base/PriorityLevel.cs index e9ce948b38..f11dd07347 100644 --- a/Perspex.Base/PriorityLevel.cs +++ b/Perspex.Base/PriorityLevel.cs @@ -10,6 +10,22 @@ namespace Perspex using System.Collections.Generic; using System.Reactive.Disposables; + /// + /// Determines how the current binding is selected for a . + /// + internal enum LevelPrecedenceMode + { + /// + /// The latest fired binding is used as the current value. + /// + Latest, + + /// + /// The latest added binding is used as the current value. + /// + Newest, + } + /// /// Stores bindings for a priority level in a . /// @@ -49,6 +65,8 @@ namespace Perspex /// private int nextIndex; + private LevelPrecedenceMode mode; + /// /// Initializes a new instance of the class. /// @@ -56,10 +74,12 @@ namespace Perspex /// A method to be called when the current value changes. public PriorityLevel( int priority, + LevelPrecedenceMode mode, Action changed) { Contract.Requires(changed != null); + this.mode = mode; this.changed = changed; this.Priority = priority; this.Value = this.directValue = PerspexProperty.UnsetValue; @@ -136,7 +156,7 @@ namespace Perspex /// The entry that changed. private void Changed(PriorityBindingEntry entry) { - if (entry.Index >= this.ActiveBindingIndex) + if (mode == LevelPrecedenceMode.Latest || entry.Index >= this.ActiveBindingIndex) { if (entry.Value != PerspexProperty.UnsetValue) { diff --git a/Perspex.Base/PriorityValue.cs b/Perspex.Base/PriorityValue.cs index b22ef91890..703b67813f 100644 --- a/Perspex.Base/PriorityValue.cs +++ b/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); } diff --git a/Perspex.Themes.Default/DropDownStyle.cs b/Perspex.Themes.Default/DropDownStyle.cs index 6c3ae734d5..3ea74713f7 100644 --- a/Perspex.Themes.Default/DropDownStyle.cs +++ b/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().Select(x => (object)x.Width), - } + [~~Popup.IsOpenProperty] = control[~~DropDown.IsDropDownOpenProperty], + [~Popup.MinWidthProperty] = control[~DropDown.BoundsProperty].Cast().Select(x => (object)x.Width), } }, }, };