3 changed files with 0 additions and 117 deletions
@ -1,39 +0,0 @@ |
|||
using System; |
|||
using Avalonia.Data; |
|||
|
|||
namespace Avalonia.PropertyStore |
|||
{ |
|||
/// <summary>
|
|||
/// An <see cref="IValueEntry"/> that holds a binding whose source observable and target
|
|||
/// property are both untyped.
|
|||
/// </summary>
|
|||
internal class UntypedBindingEntry : BindingEntryBase<object?, object?> |
|||
{ |
|||
private readonly Func<object?, bool>? _validate; |
|||
|
|||
public UntypedBindingEntry( |
|||
AvaloniaObject target, |
|||
ValueFrame frame, |
|||
AvaloniaProperty property, |
|||
IObservable<object?> source) |
|||
: base(target, frame, property, source) |
|||
{ |
|||
_validate = ((IStyledPropertyAccessor)property).ValidateValue; |
|||
} |
|||
|
|||
protected override BindingValue<object?> ConvertAndValidate(object? value) |
|||
{ |
|||
return UntypedValueUtils.ConvertAndValidate(value, Property.PropertyType, _validate); |
|||
} |
|||
|
|||
protected override BindingValue<object?> ConvertAndValidate(BindingValue<object?> value) |
|||
{ |
|||
throw new NotSupportedException(); |
|||
} |
|||
|
|||
protected override object? GetDefaultValue(Type ownerType) |
|||
{ |
|||
return ((IStyledPropertyMetadata)Property.GetMetadata(ownerType)).DefaultValue; |
|||
} |
|||
} |
|||
} |
|||
@ -1,60 +0,0 @@ |
|||
using System; |
|||
using Avalonia.Data; |
|||
using Avalonia.PropertyStore; |
|||
|
|||
namespace Avalonia.Styling |
|||
{ |
|||
internal class PropertySetterBindingInstance : UntypedBindingEntry, ISetterInstance |
|||
{ |
|||
private readonly AvaloniaObject _target; |
|||
private readonly BindingMode _mode; |
|||
|
|||
public PropertySetterBindingInstance( |
|||
AvaloniaObject target, |
|||
StyleInstance instance, |
|||
AvaloniaProperty property, |
|||
BindingMode mode, |
|||
IObservable<object?> source) |
|||
: base(target, instance, property, source) |
|||
{ |
|||
_target = target; |
|||
_mode = mode; |
|||
|
|||
if (mode == BindingMode.TwoWay && |
|||
source is not IObserver<object?>) |
|||
{ |
|||
throw new NotSupportedException( |
|||
"Attempting to bind two-way with a binding source which doesn't support it."); |
|||
} |
|||
} |
|||
|
|||
public override void Unsubscribe() |
|||
{ |
|||
_target.PropertyChanged -= PropertyChanged; |
|||
base.Unsubscribe(); |
|||
} |
|||
|
|||
protected override void Start(bool produceValue) |
|||
{ |
|||
if (!IsSubscribed) |
|||
{ |
|||
if (_mode == BindingMode.TwoWay) |
|||
{ |
|||
var observer = (IObserver<object?>)Source; |
|||
_target.PropertyChanged += PropertyChanged; |
|||
} |
|||
|
|||
base.Start(produceValue); |
|||
} |
|||
} |
|||
|
|||
private void PropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e) |
|||
{ |
|||
if (e.Property == Property && e.Priority >= BindingPriority.LocalValue) |
|||
{ |
|||
if (Frame.Owner is not null && !Frame.Owner.IsEvaluating) |
|||
((IObserver<object?>)Source).OnNext(e.NewValue); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue