Browse Source

Make ExpressionObserver accept a priority for sets.

This makes auto-expanding the treeview in DevTools work again.
pull/472/head
Steven Kirk 11 years ago
parent
commit
886fbb5458
  1. 3
      src/Markup/Perspex.Markup.Xaml/Data/Binding.cs
  2. 5
      src/Markup/Perspex.Markup/Data/ExpressionNode.cs
  3. 6
      src/Markup/Perspex.Markup/Data/ExpressionObserver.cs
  4. 9
      src/Markup/Perspex.Markup/Data/ExpressionSubject.cs
  5. 3
      src/Markup/Perspex.Markup/Data/LogicalNotNode.cs
  6. 6
      src/Markup/Perspex.Markup/Data/Plugins/IPropertyAccessor.cs
  7. 3
      src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs
  8. 5
      src/Markup/Perspex.Markup/Data/Plugins/PerspexPropertyAccessorPlugin.cs
  9. 7
      src/Markup/Perspex.Markup/Data/PropertyAccessorNode.cs

3
src/Markup/Perspex.Markup.Xaml/Data/Binding.cs

@ -107,7 +107,8 @@ namespace Perspex.Markup.Xaml.Data
targetProperty?.PropertyType ?? typeof(object),
Converter ?? DefaultValueConverter.Instance,
ConverterParameter,
FallbackValue);
FallbackValue,
Priority);
return new InstancedBinding(subject, Mode, Priority);
}

5
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 @@ namespace Perspex.Markup.Data
}
}
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<object> observer)

6
src/Markup/Perspex.Markup/Data/ExpressionObserver.cs

@ -7,6 +7,7 @@ using System.Reactive;
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 @@ namespace Perspex.Markup.Data
/// Attempts to set the value of a property expression.
/// </summary>
/// <param name="value">The value to set.</param>
/// <param name="priority">The binding priority to use.</param>
/// <returns>
/// True if the value could be set; false if the expression does not evaluate to a
/// property.
/// </returns>
public bool SetValue(object value)
public bool SetValue(object value, BindingPriority priority = BindingPriority.LocalValue)
{
IncrementCount();
@ -120,7 +122,7 @@ namespace Perspex.Markup.Data
try
{
return _node?.SetValue(value) ?? false;
return _node?.SetValue(value, priority) ?? false;
}
finally
{

9
src/Markup/Perspex.Markup/Data/ExpressionSubject.cs

@ -5,6 +5,7 @@ using System;
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 @@ namespace Perspex.Markup.Data
private readonly ExpressionObserver _inner;
private readonly Type _targetType;
private readonly object _fallbackValue;
private readonly BindingPriority _priority;
/// <summary>
/// Initializes a new instance of the <see cref="ExpressionObserver"/> class.
@ -41,12 +43,14 @@ namespace Perspex.Markup.Data
/// <param name="fallbackValue">
/// The value to use when the binding is unable to produce a value.
/// </param>
/// <param name="priority">The binding priority.</param>
public ExpressionSubject(
ExpressionObserver inner,
Type targetType,
IValueConverter converter,
object converterParameter = null,
object fallbackValue = null)
object fallbackValue = null,
BindingPriority priority = BindingPriority.LocalValue)
{
Contract.Requires<ArgumentNullException>(inner != null);
Contract.Requires<ArgumentNullException>(targetType != null);
@ -57,6 +61,7 @@ namespace Perspex.Markup.Data
Converter = converter;
ConverterParameter = converterParameter;
_fallbackValue = fallbackValue;
_priority = priority;
}
/// <summary>
@ -100,7 +105,7 @@ namespace Perspex.Markup.Data
converted = TypeUtilities.Default(type);
}
_inner.SetValue(converted);
_inner.SetValue(converted, _priority);
}
}

3
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;
}

6
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 @@ namespace Perspex.Markup.Data.Plugins
/// <param name="value">
/// The value to set. Guaranteed to be of a valid type for the property.
/// </param>
/// <param name="priority">
/// The priority with which to set the value.
/// </param>
/// <returns>
/// True if the property was set; false if the property could not be set.
/// </returns>
bool SetValue(object value);
bool SetValue(object value, BindingPriority priority);
}
}

3
src/Markup/Perspex.Markup/Data/Plugins/InpcPropertyAccessorPlugin.cs

@ -6,6 +6,7 @@ using System.ComponentModel;
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 @@ namespace Perspex.Markup.Data.Plugins
}
}
public bool SetValue(object value)
public bool SetValue(object value, BindingPriority priority)
{
if (_property.CanWrite)
{

5
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 @@ namespace Perspex.Markup.Data.Plugins
_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;
}

7
src/Markup/Perspex.Markup/Data/PropertyAccessorNode.cs

@ -8,6 +8,7 @@ using System.Reflection;
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 @@ namespace Perspex.Markup.Data
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;

Loading…
Cancel
Save