From 886fbb545858ca41475c855566fb9d4877947fc5 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 9 Mar 2016 01:14:36 +0100 Subject: [PATCH] Make ExpressionObserver accept a priority for sets. This makes auto-expanding the treeview in DevTools work again. --- src/Markup/Perspex.Markup.Xaml/Data/Binding.cs | 3 ++- src/Markup/Perspex.Markup/Data/ExpressionNode.cs | 5 +++-- src/Markup/Perspex.Markup/Data/ExpressionObserver.cs | 6 ++++-- src/Markup/Perspex.Markup/Data/ExpressionSubject.cs | 9 +++++++-- src/Markup/Perspex.Markup/Data/LogicalNotNode.cs | 3 ++- .../Perspex.Markup/Data/Plugins/IPropertyAccessor.cs | 6 +++++- .../Data/Plugins/InpcPropertyAccessorPlugin.cs | 3 ++- .../Data/Plugins/PerspexPropertyAccessorPlugin.cs | 5 +++-- src/Markup/Perspex.Markup/Data/PropertyAccessorNode.cs | 7 ++++--- 9 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/Markup/Perspex.Markup.Xaml/Data/Binding.cs b/src/Markup/Perspex.Markup.Xaml/Data/Binding.cs index 776a78d83ac..588cc12f0e4 100644 --- a/src/Markup/Perspex.Markup.Xaml/Data/Binding.cs +++ b/src/Markup/Perspex.Markup.Xaml/Data/Binding.cs @@ -107,7 +107,8 @@ public InstancedBinding Initiate( targetProperty?.PropertyType ?? typeof(object), Converter ?? DefaultValueConverter.Instance, ConverterParameter, - FallbackValue); + FallbackValue, + Priority); return new InstancedBinding(subject, Mode, Priority); } diff --git a/src/Markup/Perspex.Markup/Data/ExpressionNode.cs b/src/Markup/Perspex.Markup/Data/ExpressionNode.cs index 100bb3d07f6..e989a721772 100644 --- a/src/Markup/Perspex.Markup/Data/ExpressionNode.cs +++ b/src/Markup/Perspex.Markup/Data/ExpressionNode.cs @@ -3,6 +3,7 @@ using System; using System.Reactive.Subjects; +using Perspex.Data; namespace Perspex.Markup.Data { @@ -76,9 +77,9 @@ public WeakReference CurrentValue } } - public virtual bool SetValue(object value) + public virtual bool SetValue(object value, BindingPriority priority) { - return Next?.SetValue(value) ?? false; + return Next?.SetValue(value, priority) ?? false; } public virtual IDisposable Subscribe(IObserver observer) diff --git a/src/Markup/Perspex.Markup/Data/ExpressionObserver.cs b/src/Markup/Perspex.Markup/Data/ExpressionObserver.cs index 8bbedd52cc4..e5b0d1ac783 100644 --- a/src/Markup/Perspex.Markup/Data/ExpressionObserver.cs +++ b/src/Markup/Perspex.Markup/Data/ExpressionObserver.cs @@ -7,6 +7,7 @@ using System.Reactive.Disposables; using System.Reactive.Linq; using System.Reactive.Subjects; +using Perspex.Data; using Perspex.Markup.Data.Plugins; namespace Perspex.Markup.Data @@ -105,11 +106,12 @@ public ExpressionObserver( /// Attempts to set the value of a property expression. /// /// The value to set. + /// The binding priority to use. /// /// True if the value could be set; false if the expression does not evaluate to a /// property. /// - public bool SetValue(object value) + public bool SetValue(object value, BindingPriority priority = BindingPriority.LocalValue) { IncrementCount(); @@ -120,7 +122,7 @@ public bool SetValue(object value) try { - return _node?.SetValue(value) ?? false; + return _node?.SetValue(value, priority) ?? false; } finally { diff --git a/src/Markup/Perspex.Markup/Data/ExpressionSubject.cs b/src/Markup/Perspex.Markup/Data/ExpressionSubject.cs index 6b12c6dede4..95b8c7ac4d9 100644 --- a/src/Markup/Perspex.Markup/Data/ExpressionSubject.cs +++ b/src/Markup/Perspex.Markup/Data/ExpressionSubject.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Reactive.Linq; using System.Reactive.Subjects; +using Perspex.Data; using Perspex.Utilities; namespace Perspex.Markup.Data @@ -18,6 +19,7 @@ public class ExpressionSubject : ISubject, IDescription private readonly ExpressionObserver _inner; private readonly Type _targetType; private readonly object _fallbackValue; + private readonly BindingPriority _priority; /// /// Initializes a new instance of the class. @@ -41,12 +43,14 @@ public ExpressionSubject(ExpressionObserver inner, Type targetType) /// /// The value to use when the binding is unable to produce a value. /// + /// The binding priority. public ExpressionSubject( ExpressionObserver inner, Type targetType, IValueConverter converter, object converterParameter = null, - object fallbackValue = null) + object fallbackValue = null, + BindingPriority priority = BindingPriority.LocalValue) { Contract.Requires(inner != null); Contract.Requires(targetType != null); @@ -57,6 +61,7 @@ public ExpressionSubject( Converter = converter; ConverterParameter = converterParameter; _fallbackValue = fallbackValue; + _priority = priority; } /// @@ -100,7 +105,7 @@ public void OnNext(object value) converted = TypeUtilities.Default(type); } - _inner.SetValue(converted); + _inner.SetValue(converted, _priority); } } diff --git a/src/Markup/Perspex.Markup/Data/LogicalNotNode.cs b/src/Markup/Perspex.Markup/Data/LogicalNotNode.cs index a2941684b47..9a1eec8d83c 100644 --- a/src/Markup/Perspex.Markup/Data/LogicalNotNode.cs +++ b/src/Markup/Perspex.Markup/Data/LogicalNotNode.cs @@ -4,12 +4,13 @@ using System; using System.Globalization; using System.Reactive.Linq; +using Perspex.Data; namespace Perspex.Markup.Data { internal class LogicalNotNode : ExpressionNode { - public override bool SetValue(object value) + public override bool SetValue(object value, BindingPriority priority) { return false; } diff --git a/src/Markup/Perspex.Markup/Data/Plugins/IPropertyAccessor.cs b/src/Markup/Perspex.Markup/Data/Plugins/IPropertyAccessor.cs index 772bbbafe95..776993b2202 100644 --- a/src/Markup/Perspex.Markup/Data/Plugins/IPropertyAccessor.cs +++ b/src/Markup/Perspex.Markup/Data/Plugins/IPropertyAccessor.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; +using Perspex.Data; namespace Perspex.Markup.Data.Plugins { @@ -27,9 +28,12 @@ public interface IPropertyAccessor : IDisposable /// /// The value to set. Guaranteed to be of a valid type for the property. /// + /// + /// The priority with which to set the value. + /// /// /// True if the property was set; false if the property could not be set. /// - bool SetValue(object value); + bool SetValue(object value, BindingPriority priority); } } diff --git a/src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs b/src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs index 4d53fdaea49..3a71859b4ce 100644 --- a/src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs +++ b/src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reactive.Linq; using System.Reflection; +using Perspex.Data; using Perspex.Utilities; namespace Perspex.Markup.Data.Plugins @@ -106,7 +107,7 @@ public void Dispose() } } - public bool SetValue(object value) + public bool SetValue(object value, BindingPriority priority) { if (_property.CanWrite) { diff --git a/src/Markup/Perspex.Markup/Data/Plugins/PerspexPropertyAccessorPlugin.cs b/src/Markup/Perspex.Markup/Data/Plugins/PerspexPropertyAccessorPlugin.cs index 9f50359570d..411fcc1555a 100644 --- a/src/Markup/Perspex.Markup/Data/Plugins/PerspexPropertyAccessorPlugin.cs +++ b/src/Markup/Perspex.Markup/Data/Plugins/PerspexPropertyAccessorPlugin.cs @@ -3,6 +3,7 @@ using System; using System.Reactive.Linq; +using Perspex.Data; namespace Perspex.Markup.Data.Plugins { @@ -95,11 +96,11 @@ public void Dispose() _subscription = null; } - public bool SetValue(object value) + public bool SetValue(object value, BindingPriority priority) { if (!_property.IsReadOnly) { - Instance.SetValue(_property, value); + Instance.SetValue(_property, value, priority); return true; } diff --git a/src/Markup/Perspex.Markup/Data/PropertyAccessorNode.cs b/src/Markup/Perspex.Markup/Data/PropertyAccessorNode.cs index 9208c9d0813..1aa703ff8ff 100644 --- a/src/Markup/Perspex.Markup/Data/PropertyAccessorNode.cs +++ b/src/Markup/Perspex.Markup/Data/PropertyAccessorNode.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows.Input; +using Perspex.Data; using Perspex.Markup.Data.Plugins; namespace Perspex.Markup.Data @@ -26,17 +27,17 @@ public PropertyAccessorNode(string propertyName) public Type PropertyType => _accessor?.PropertyType; - public override bool SetValue(object value) + public override bool SetValue(object value, BindingPriority priority) { if (Next != null) { - return Next.SetValue(value); + return Next.SetValue(value, priority); } else { if (_accessor != null) { - return _accessor.SetValue(value); + return _accessor.SetValue(value, priority); } return false;