|
|
@ -7,7 +7,9 @@ namespace Avalonia.Styling |
|
|
{ |
|
|
{ |
|
|
internal class PropertySetterBindingInstance : BindingEntry, ISetterInstance |
|
|
internal class PropertySetterBindingInstance : BindingEntry, ISetterInstance |
|
|
{ |
|
|
{ |
|
|
private readonly IDisposable? _twoWaySubscription; |
|
|
private readonly AvaloniaObject _target; |
|
|
|
|
|
private readonly BindingMode _mode; |
|
|
|
|
|
private IDisposable? _twoWaySubscription; |
|
|
|
|
|
|
|
|
public PropertySetterBindingInstance( |
|
|
public PropertySetterBindingInstance( |
|
|
AvaloniaObject target, |
|
|
AvaloniaObject target, |
|
|
@ -17,18 +19,14 @@ namespace Avalonia.Styling |
|
|
IObservable<object?> source) |
|
|
IObservable<object?> source) |
|
|
: base(instance, property, source) |
|
|
: base(instance, property, source) |
|
|
{ |
|
|
{ |
|
|
if (mode == BindingMode.TwoWay) |
|
|
_target = target; |
|
|
|
|
|
_mode = mode; |
|
|
|
|
|
|
|
|
|
|
|
if (mode == BindingMode.TwoWay && |
|
|
|
|
|
source is not IObserver<object?>) |
|
|
{ |
|
|
{ |
|
|
// TODO: HUGE HACK FIXME
|
|
|
throw new NotSupportedException( |
|
|
if (source is IObserver<object?> observer) |
|
|
"Attempting to bind two-way with a binding source which doesn't support it."); |
|
|
{ |
|
|
|
|
|
_twoWaySubscription = target.GetObservable(property).Skip(1).Subscribe(observer); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
throw new NotSupportedException( |
|
|
|
|
|
"Attempting to bind two-way with a binding source which doesn't support it."); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -37,5 +35,16 @@ namespace Avalonia.Styling |
|
|
_twoWaySubscription?.Dispose(); |
|
|
_twoWaySubscription?.Dispose(); |
|
|
base.Unsubscribe(); |
|
|
base.Unsubscribe(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected override void Start(bool produceValue) |
|
|
|
|
|
{ |
|
|
|
|
|
if (_mode == BindingMode.TwoWay) |
|
|
|
|
|
{ |
|
|
|
|
|
var observer = (IObserver<object?>)Source; |
|
|
|
|
|
_twoWaySubscription = _target.GetObservable(Property).Skip(1).Subscribe(observer); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
base.Start(produceValue); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|