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

11.1.0 - Two-way binding doesn't update source property if target property has not been changed #16466

Open
pavelovcharov opened this issue Jul 25, 2024 · 0 comments

Comments

@pavelovcharov
Copy link
Contributor

Describe the bug

A two-way binding to a property whose value will not change (for example, binding to the TabControl.SelectedIndex property) no longer updates the value of the source property

To Reproduce

Create a test as shown in the following code snippet

public class UnitTest1
{
    [Fact]
    public void Test1()
    {
        ViewModel vm = new ViewModel();

        var tabControl = new TabControl();
        var tabItem = new TabItem();
        tabControl.Items.Add(tabItem);
        tabControl.Bind(TabControl.SelectedIndexProperty,
            new Binding(nameof(ViewModel.SelectedIndex), BindingMode.TwoWay) { Source = vm });

        Assert.Equal(0, tabControl.SelectedIndex);
        Assert.Equal(0, vm.SelectedIndex);
    }
}

public class ViewModel : AvaloniaObject
{
    public static readonly StyledProperty<int> SelectedIndexProperty =
        AvaloniaProperty.Register<ViewModel, int>(nameof(SelectedIndex), -1);

    public int SelectedIndex
    {
        get => GetValue(SelectedIndexProperty);
        set => SetValue(SelectedIndexProperty, value);
    }
}

The vm.SelectedIndex property will have value -1

Expected behavior

The source property should be update in this case

Avalonia version

11.1.0

OS

No response

Additional context

No response

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