Stream binding operator does not work in two way mode for TextBox, NumericUpDown
Opened this issue · 2 comments
Describe the bug
I might be misunderstanding how it is supposed to work, but when i bind the Text property of Text or Value property of NumericUpDown in two way mode to a Subject
, using stream binding operator, i get no updates in the viewmodel when changing the state of the control on the ui. Please see the attached example.
However, it works very well for ScrollView.Offset property.
am i getting something wrong?
To Reproduce
Could be reproduced easily in the avalonia starter template.
Mainwindow.xaml:
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="using:AvaloniaApplication1.ViewModels"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaApplication1.Views.MainWindow"
x:DataType="vm:MainWindowViewModel"
Icon="/Assets/avalonia-logo.ico"
Title="AvaloniaApplication1">
<TextBox Text="{Binding Foo^, Mode=TwoWay}"></TextBox>
</Window>
MainwindowViewModel.cs:
using System;
using System.Reactive.Subjects;
using ReactiveUI;
using Console = System.Console;
using System.Reactive.Linq;
using System.Reactive;
namespace AvaloniaApplication1.ViewModels;
public partial class MainWindowViewModel : ReactiveObject
{
private BehaviorSubject<string> foo = new("hello");
public BehaviorSubject<string> Foo => foo;
public MainWindowViewModel()
{
foo.Subscribe(x => Console.WriteLine(x));
}
}
Everything else is left unchanged in the starter template.
I have only added ReactiveUI - 20.1.63
package.
I see "hello" appear in th econtrol but then I expect values printed to the console when i change the value of the TextBox on the ui.
Thanks!
Expected behavior
Just as if i have bound the Offset
property of a ScrollViewer
, and listened for updates, i get console messages printed upon change.
Avalonia version
11.2.1
OS
Linux
Additional context
No response
I don't think stream operator ever supported two-way bindings (i.e. assuming it should write back to IObserver/Subject).
Implementation also only refers to one-way listening: https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/Data/Core/Plugins/IStreamPlugin.cs#L8
Thanks for checking, tha explains a lot! But then the question arises, how Scrollviewer.Offset writeback works?