|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using System; |
|
|
|
using System.Runtime.ExceptionServices; |
|
|
|
using Avalonia.Utilities; |
|
|
|
|
|
|
|
namespace Avalonia.Data.Core.Plugins |
|
|
|
{ |
|
|
|
@ -60,11 +61,10 @@ namespace Avalonia.Data.Core.Plugins |
|
|
|
return AvaloniaPropertyRegistry.Instance.FindRegistered(o, propertyName); |
|
|
|
} |
|
|
|
|
|
|
|
private class Accessor : PropertyAccessorBase, IObserver<object?> |
|
|
|
private class Accessor : PropertyAccessorBase, IWeakEventSubscriber<AvaloniaPropertyChangedEventArgs> |
|
|
|
{ |
|
|
|
private readonly WeakReference<AvaloniaObject> _reference; |
|
|
|
private readonly AvaloniaProperty _property; |
|
|
|
private IDisposable? _subscription; |
|
|
|
|
|
|
|
public Accessor(WeakReference<AvaloniaObject> reference, AvaloniaProperty property) |
|
|
|
{ |
|
|
|
@ -95,29 +95,45 @@ namespace Avalonia.Data.Core.Plugins |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
protected override void SubscribeCore() |
|
|
|
void IWeakEventSubscriber<AvaloniaPropertyChangedEventArgs>. |
|
|
|
OnEvent(object? notifyPropertyChanged, WeakEvent ev, AvaloniaPropertyChangedEventArgs e) |
|
|
|
{ |
|
|
|
_subscription = Instance?.GetObservable(_property).Subscribe(this); |
|
|
|
if (e.Property == _property) |
|
|
|
{ |
|
|
|
SendCurrentValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected override void UnsubscribeCore() |
|
|
|
protected override void SubscribeCore() |
|
|
|
{ |
|
|
|
_subscription?.Dispose(); |
|
|
|
_subscription = null; |
|
|
|
SubscribeToChanges(); |
|
|
|
SendCurrentValue(); |
|
|
|
} |
|
|
|
|
|
|
|
void IObserver<object?>.OnCompleted() |
|
|
|
protected override void UnsubscribeCore() |
|
|
|
{ |
|
|
|
var instance = Instance; |
|
|
|
|
|
|
|
if (instance != null) |
|
|
|
WeakEvents.AvaloniaPropertyChanged.Unsubscribe(instance, this); |
|
|
|
} |
|
|
|
|
|
|
|
void IObserver<object?>.OnError(Exception error) |
|
|
|
private void SendCurrentValue() |
|
|
|
{ |
|
|
|
ExceptionDispatchInfo.Capture(error).Throw(); |
|
|
|
try |
|
|
|
{ |
|
|
|
var value = Value; |
|
|
|
PublishValue(value); |
|
|
|
} |
|
|
|
catch { } |
|
|
|
} |
|
|
|
|
|
|
|
void IObserver<object?>.OnNext(object? value) |
|
|
|
private void SubscribeToChanges() |
|
|
|
{ |
|
|
|
PublishValue(value); |
|
|
|
var instance = Instance; |
|
|
|
|
|
|
|
if (instance != null) |
|
|
|
WeakEvents.AvaloniaPropertyChanged.Subscribe(instance, this); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|