Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream binding operator does not work in two way mode for TextBox, NumericUpDown #17768

Open
legezam opened this issue Dec 13, 2024 · 2 comments

Comments

@legezam
Copy link

legezam commented Dec 13, 2024

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

@maxkatz6
Copy link
Member

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

@legezam
Copy link
Author

legezam commented Dec 14, 2024

Thanks for checking, tha explains a lot! But then the question arises, how Scrollviewer.Offset writeback works?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants