Skip to content

Commit d557e13

Browse files
authored
Merge pull request #89 from bj-rn/feat/binding
corrected binding part
2 parents e34f989 + cbfb850 commit d557e13

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

VL.Avalonia/src/Data/Binding.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ public void SetChannel(IChannel<TValue>? channel)
7474

7575
protected virtual void Bind()
7676
{
77+
_subscriptions?.Clear();
78+
7779
if (_input != null && _property != null)
7880
{
79-
var channelToBind = (_channel ?? _internalChannel) as IObservable<object?>;
81+
var channel = (_channel ?? _internalChannel);
8082

81-
if (channelToBind != null)
83+
if (channel != null)
8284
{
83-
_subscriptions?.Clear();
85+
var channelToBind = channel.Select(x => (object?)x);
8486

8587
_subscriptions?.Add(_input.Bind(_property, channelToBind));
8688

@@ -89,8 +91,14 @@ protected virtual void Bind()
8991
case SupportedBindingMode.TwoWay:
9092
var observable = _input.GetObservable(_property).Skip(1);
9193

92-
observable.Subscribe(x =>
93-
(_channel ?? _internalChannel).OnNext((TValue)x)
94+
_subscriptions?.Add(
95+
observable.Subscribe(x =>
96+
{
97+
if (x is TValue v)
98+
channel.OnNext(v);
99+
else if (x is null)
100+
channel.OnNext(default!);
101+
})
94102
);
95103

96104
return;
@@ -100,8 +108,6 @@ protected virtual void Bind()
100108
}
101109
}
102110
}
103-
104-
_subscriptions?.Clear();
105111
}
106112

107113
public void Dispose()

0 commit comments

Comments
 (0)